-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-Linked Storage.c
67 lines (67 loc) · 1.46 KB
/
list-Linked Storage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct listnode
{
int data_space;
struct listnode *next;//next 是这个指针变量的名称
};
typedef struct listnode *listpointer;
listpointer creat(int *a,int len){
listpointer head=(listpointer)malloc(sizeof(struct listnode));
head->data_space=a[0];
int c=1;
for (int i = 0; i < len-1; i++)
{
listpointer p=(listpointer)malloc(sizeof(struct listnode));
p->next=head->next;
head->next=p;
p->data_space=a[c];
c=c+1;
}
printf("\n");
return head;
}
int find_node(listpointer p,int a){
int c=1;
for(int i=0;p!=NULL;i++){
if (p->data_space==a){
return c;
}
c=c+1;p=p->next;
};
return 0;
}
int insert_node(listpointer p,int a){
listpointer e=(listpointer)malloc(sizeof(struct listnode));
e->data_space=a;e->next=p->next;p->next=e;
return 1;
}
int del(listpointer p,int a){
listpointer e;
for (int i = 0; p->next!=NULL; i++)
{
if (p->next->data_space==a){
e=p->next;p->next=p->next->next;
free(e);
return 1;
}
p=p->next;
}
return 0;
}
int clear_all(listpointer p){
listpointer q;
for (int i = 0; p!=NULL ; i++)
{
q=p->next;
free(p);
p=q;
}
return 0;
}
int main(){
int a[]={1,2,3,4,5};listpointer head=creat(a,5);//创建链表
clear_all(head);
return 0;
}