/* **名称:实现线性表链式存储结构的基本操作(带根节点)——静态链表 **Author:yzs **Time:2021.9.28 */ #include #include #define MAXSIZE 20 //数组实际长度只有MAXSIZE-2 typedef struct { int value; int cur;//游标 }component; int main() { void print_linklist(FILE *op,component *array,int head); void init_list(FILE *ip,component *array); void insert(component *array,int index,int value); void delete(component *array,int index); int list_length(component *array); void sort(component *array); FILE *ip,*op; FILE *ip2; ip = fopen("input.txt", "r"); ip2 = fopen("input2.txt", "r"); op = fopen("output.txt", "w"); component array[MAXSIZE];//新建结构体数组作为静态链表 init_list(ip,array); print_linklist(op,array,MAXSIZE-1); fprintf(op,"\n"); insert(array,3,99); delete(array,5); print_linklist(op,array,MAXSIZE-1); sort(array); fprintf(op,"\n"); print_linklist(op,array,MAXSIZE-1); //printf("%d",list_length(array)); fclose(ip); fclose(ip2); fclose(op); } void init_list(FILE *ip,component *array)//链表数据初始化 { int mallocArr(component *array); for (int i=0; iarray[next].value) { int temp_value=array[temp].value; array[temp].value=array[next].value; array[next].value=temp_value; } temp=next; next=array[next].cur; } } }