第三十七次发博不知道用什么标题好

链表

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 typedef struct nodd{
 4     int data;
 5     struct node *next;
 6 }slist;
 7 
 8 slist* creat(slist *L,int a[],int n){                    //头插 
 9     slist *p=L;
10     int i;
11     for(i=0;i<n;i++){
12         p=(slist*)malloc(sizeof(slist));
13         p->data=a[i];
14         p->next=L->next;
15         p=L;
16     }
17         return L;
18 }
19 
20 void delet(slist *L,int i,int x){                        //删除 
21     slist *p=L;
22     int j;
23     while(p!=NULL)
24     {
25         if(x==p->data)
26         break;
27         L=p;
28         p=p->next;    
29     }
30         L->next=p->next;
31         free(p);
32 }
33 
34 void insert(slist *L,int n,int x){                        //插入 
35     slist *p,*s=L;
36     p=(slist*)malloc(sizeof(slist));
37     while(p!=NULL)
38     {
39         if(x==s->data)
40         break;
41         L=s;
42         s=s->next;    
43     }
44         p->data=n;
45         p->next=s->next;
46         L->next=p;
47 }
48 
49 void destroy(slist *L){                                //销毁 
50     slist *pre=L,*p=L->next;
51     while(p!=NULL)
52     {
53         free(pre);
54         pre=p;
55         p=p->next;
56     }
57         free(pre);
58 }
59 
60 void print(slist *L){                                    //输出 
61     slist *p;
62     while(p!=NULL)
63     {
64         scanf("%d",p->data);
65         p=p->next;
66     }
67 }
68 
69 int Length(slist *L){                                        //链表长 
70     int n;
71     slist *p=L;
72     while(L!=NULL){
73         n++;
74         p=p->next;
75     }
76         return n;
77 }
78 
79 void insertlast(slist *L,int a[],int n){                            //尾插 
80     slist *p;
81     int i;
82     for(i=0;i<n;i++)
83     {
84         p=(slist*)maloc(sizeof(slist));
85         p->data=a[i];
86         L->next=p;
87         L=p;
88         
89     }
90 }

猜你喜欢

转载自www.cnblogs.com/shi-yuan/p/10909522.html