-
Notifications
You must be signed in to change notification settings - Fork 0
/
表.c
107 lines (100 loc) · 1.5 KB
/
表.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<stdio.h>
typedef struct test {
int a;
struct test* b;
}date;
int main()
{
int isempty(date * a);
date* find(int x, date * a);
void deleat(int x, date * a);
void insert(int x, date * a, date * b);
date* findprevious(int x, date * a);
void deletelist(date * a);
int n = 0;
date* p1;
date* p2;
date* head;
p1 = p2 = (date*)malloc(sizeof(date));
scanf_s("%d", &p1->a);
head = NULL;
while (p1->a != 0)
{
n = n + 1;
if (n == 1)
head = p1;
else
p2->b = p1;
p2 = p1;
p1 = (date*)malloc(sizeof(date));
scanf_s("%d", &p1->a);
}
printf("%d", isempty(head));
printf("%p", find(2, head));
deleat(3, head);
insert(3, head, findprevious(3, head));
deletelist(head);
return 0;
}
int isempty(date* a)
{
return a->a == NULL;
}
int islast(date* a)
{
return a->b == 0;
}
date* find(int x, date* a)
{
date* p;
p = a->b;
while (p != NULL && p->a != x)
{
p = p->b;
}
return p;
}
void deleat(int x, date* a)
{
date* findprevious(int x, date * a);
date* p, * tem;
p = findprevious(x, a);
if (!islast(p, a))
{
tem = p->b;
p->b = tem->b;
free(tem);
}
}
date* findprevious(int x, date* a)
{
date* p;
p = a;
while (p->b != NULL && p->b->a != x)
{
p = p->b;
}
return p;
}
void insert(int x, date* a, date* b)
{
date* tem;
tem = (date*)malloc(sizeof(date));
if (tem = NULL)
printf(" out of space");
tem->a = x;
tem->b = b->b;
b->b = tem;
}
void deletelist(date* a)
{
date* p, * tem;
p = a->b;
a->b = NULL;
while (p != NULL)
{
tem = p->b;
free(p);
p = tem;
}
}