第三十八次发博不知道用什么标题好
1 #include<stdio.h> 2 #include<stdlib.h> 3 typedef struct node{ 4 int data; 5 struct node *next; 6 }Slist; 7 Slist* Creatlist(Slist *L,int a[],int n) 8 { 9 Slist *s; 10 int i; 11 L=(Slist*)malloc(sizeof(Slist)); 12 L->next=NULL; 13 for(i=0;i<n;i++) 14 { 15 s=(Slist*)malloc(sizeof(Slist)); 16 s->data=a[i]; 17 s->next=L->next; 18 L->next=s; 19 } 20 return L; 21 } 22 23 Slist * Creat1(Slist *L,int a[],int n) 24 { 25 Slist *s; 26 int i; 27 L=(Slist*)malloc(sizeof(Slist)); 28 for(i=0;i<n;i++) 29 { 30 s=(Slist*)malloc(sizeof(Slist)); 31 s->data=a[i]; 32 L->next=s; 33 L=s; 34 } 35 return L; 36 } 37 void Insert(Slist *L,int x,int i) 38 { 39 Slist *s,*p=L; 40 int j=0; 41 while(p!=NULL&&j<i-1) 42 { 43 j++; 44 p=p->next; 45 } 46 s=(Slist*)malloc(sizeof(Slist)); 47 s->data=x; 48 s->next=p->next; 49 p->next=s; 50 } 51 52 53 int Lenth(Slist*L) 54 { 55 int n; 56 while(L->next!=NULL) 57 { 58 n++; 59 L=L->next; 60 } 61 return n; 62 } 63 64 int Delet(Slist *L,int i) 65 { 66 int j; 67 Slist *p; 68 while(L!=NULL&&j<i) 69 { 70 j++; 71 L=L->next; 72 } 73 if(L==NULL) 74 { 75 return -1; 76 } 77 else 78 { 79 p=L->next; 80 L->next=p->next; 81 free(p); 82 } 83 return 1; 84 } 85 86 int Findlocation(Slist *L,int x,int *s) 87 { 88 int i,j; 89 Slist *p=L; 90 while(p->next!=NULL) 91 { 92 p=p->next; 93 i++; 94 } 95 if(p->data==x) 96 { 97 *s=i; 98 s++; 99 j++; 100 } 101 return j; 102 } 103 104 void Destorylist(Slist *L) 105 { 106 Slist *pre=L,*p=L->next; 107 while(p!=NULL) 108 { 109 free(pre); 110 pre=p; 111 p=pre->next; 112 } 113 free(pre); 114 } 115 116 void Printlist(Slist *L) 117 118 { 119 Slist *p=L->next; 120 while(p!=NULL) 121 { 122 scanf("%d",p->data); 123 p=p->next; 124 } 125 } 126
多做事少做梦