顺序表的插入排序操作:
#include "SEQUENCE.h" //主函数,先初始化,再插入
#include <stdio.h>
#include <stdlib.h>
int input()
{
int m;
scanf("%d",&m);
return m;
}
int main()
{
sequ list;
int ret, p, i;
ret = SEQUENCEinit(&list);
if(ret == SUCCESS)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
for(i = 0; i < 5; i++)
{
ret = sequenceinsertsort(&list, i + 1, input);
}
for(i = 0; i < 5; i++)
{
printf("%d ",list.data[i]);
}
return 0;
}
int sequenceinsertsort(sequ *s, int p, int (*qq)()) //设置函数指针用键盘输入获得数字
{
int i = 0;
fffff tmp;
s->data[p - 1] = qq();
s->length++;
for(i = 0; i < s->length; i++)
{
if(s->data[p - 1] < s->data[i]) //每插一个就进行比较排序,
{
tmp = s->data[p - 1];
s->data[p - 1] = s->data[i];
s->data[i] = tmp;
}
}
}
头文件无多大变化,只需在头文件中添加一下函数的声明