-
Notifications
You must be signed in to change notification settings - Fork 0
/
链表.cpp
124 lines (104 loc) · 2.14 KB
/
链表.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"list.h"
/*int count = 0;
student* creat()
{
student *pHead = NULL;
student *pNew, *pEnd;
pEnd = pNew = (student*)malloc(sizeof(student));
printf("please first enter Name,then Number\n");
scanf_s("%s", pNew->cName,20);
scanf_s("%d", &pNew->iNumber);
while (pNew->iNumber != 0)
{
count++;
if (count == 1)
{
pNew->pNext = pHead;
pEnd = pNew;
pHead = pNew;
}
else
{
pNew->pNext = NULL;
pEnd->pNext = pNew;
pEnd = pNew;
}
pNew = (student*)malloc(sizeof(student));
scanf_s("%s", pNew->cName,20);
scanf_s("%d", &pNew->iNumber);
}
free(pNew);
return pHead;
}
void print(student *pHead)
{
student *pTemp;
int index = 1;
printf("---the list has %d members:---\n", count);
printf("\n");
pTemp = pHead;
while (pTemp != NULL)
{
printf("the NO.%d member is:\n", index);
printf("the name is: %s\n", pTemp->cName);
printf("the number is: %d\n", pTemp->iNumber);
printf("\n");
pTemp = pTemp->pNext;
index++;
}
}
student* print_head(student *pHead)
{
student *pNew;
printf("---input memeber at first---\n");
pNew = (student*)malloc(sizeof(student));
scanf_s("%s", pNew->cName, 20);
scanf_s("%d", &pNew->iNumber);
pNew->pNext = pHead;
pHead = pNew;
count++;
return pHead;
}
void Delete(student *pHead,int index)
{
int i;
student *pTemp;
student *pPre;
pTemp = pHead;
pPre = pTemp;
printf("---delete NO.%d member---\n", index);
for (i = 1; i < index; i++)
{
pPre = pTemp;
pTemp = pTemp->pNext;
}
pPre->pNext = pTemp->pNext;
free(pTemp);
count--;
}*/
int main()
{
list *pHead=NULL, *node;
list *pHead1 = NULL;
char del[10], filename[50];
gets_s(filename, 50);
pHead = creat();
printlist(pHead);
savelist(pHead, filename);
/*freelist(pHead);
printlist(pHead);*/
pHead1 = loadlist(filename);
printlist(pHead1);
/*node = getnode();
pHead = insertlist(pHead, node);
printlist(pHead);
printf("del?:");
rewind(stdin);
gets_s(del, 10);
pHead = deletelist(pHead, del);
printlist(pHead);*/
return 0;
}