1 #include <stdio.h> 2 #include <stdlib.h> 3 #define OK 1 4 #define NO 0 5 #define MAXSIZE 20 6 typedef int bool; 7 int nn = 0; 8 9 typedef struct 10 { 11 int data[MAXSIZE]; 12 int len; 13 } Sqlist; 14 void initList(Sqlist *L) ///传递结点地址而已,怎么会初始链表 15 { 16 L->len = 0; 17 } 18 int findElem(Sqlist L, int n) 19 { 20 int e; 21 if (n>L.len) 22 return 0; 23 return L.data[n - 1]; 24 } 25 bool listInsert(Sqlist *L, int n, int data) 26 { 27 int i; 28 if (L->len == MAXSIZE || n>L->len + 1) 29 return 0; 30 31 32 for (i = L->len + 1; i >= n; i--) 33 { 34 if (L->len == MAXSIZE - 1) 35 break; 36 L->data[i] = L->data[i - 1]; 37 } 38 L->data[n - 1] = ++nn; 39 L->len++; 40 return 1; 41 } 42 bool listDelete(Sqlist *L, int n, int *e) 43 { 44 int i; 45 if (L->len == 0) 46 return 0; 47 for (i = n - 1; i <= MAXSIZE - 1; i++) 48 { 49 if (i == MAXSIZE - 1) 50 break; 51 L->data[i] = L->data[i + 1]; 52 } 53 L->len--; 54 return 1; 55 56 } 57 58 void showList(Sqlist L) 59 { 60 int i; 61 for (i = 0; i<L.len; i++){ 62 printf("%d ", L.data[i]); 63 } 64 } 65 void main222() 66 { 67 Sqlist L; 68 initList(&L); ///这怎么就把结点初始化为链表了? 69 int i; 70 int temp; 71 for (i = 1; i <= 5; i++) 72 { 73 if (!listInsert(&L, i, i)) 74 printf("no"); 75 } 76 77 showList(L); 78 79 }