1 #include<stdio.h> 2 #include<stdlib.h> 3 typedef int Elemtype; 4 typedef struct node{ 5 int data; 6 struct node *next; 7 }Slink; 8 9 void Creatlist(Slink *L) 10 { 11 L->next=NULL; 12 } 13 14 Slink * Creatlist(Slink *L,Elemtype a[],int n) //头插 15 { 16 Slink *s; 17 int i; 18 for(i=0;i<n;i++) 19 { 20 s = (Slink*)malloc(sizeof(Slink)); 21 s->data=a[i]; 22 s->next=L->next; 23 L->next=s; 24 } 25 return L; 26 } 27 28 int Insert(Slink *L,Elemtype x,int i) //插入 29 { 30 Slink *p=L,*s; 31 int j=0; 32 while(p!=NULL&&j<i=1) 33 { 34 j++; 35 p=p->next; 36 } 37 if(p==NULL) 38 return 0; 39 else 40 { 41 s = (Slink*)malloc(sizeof(Slink)); 42 s->data=x 43 s->next=p->next; 44 p->next=s; 45 return 1; 46 } 47 } 48 49 int Delet(Slink*L,int i) 50 { 51 Slink *p=L,*s; 52 int j; 53 while(p->next!=NULL&&j<i) 54 { 55 j++; 56 p=p->next; 57 } 58 if(p==NULL) 59 return 0; 60 else 61 { 62 s=p->next; 63 s->next=p->next; 64 free(p); 65 } 66 67 } 68
睡觉
原文:https://www.cnblogs.com/shi-yuan/p/10884302.html