forked from nauvalwali/Task_4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
115 lines (105 loc) · 1.81 KB
/
list.cpp
File metadata and controls
115 lines (105 loc) · 1.81 KB
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
#include <iostream>
#include "list.h"
using namespace std;
void createList(List &L)
{
First(L) = NULL;
}
address alokasi(infotype x)
{
address P = new elemenList;
Info(P) = x;
Next(P) = NULL;
return P;
}
void dealokasi(address &P)
{
delete P;
}
void insertFirst(List &L, address P)
{
if (First(L) == NULL)
{
First(L) = P;
Next(P) = First(L);
Prev(P) = First(L);
Last(L) = First(L);
}
else
{
Next(P) = First(L);
Prev(P) = Last(L);
Next(Last(L)) = P;
Prev(First(L)) = P;
First(L) = P;
}
}
void insertLast(List &L, address P)
{
if (First(L) == NULL)
{
First(L) = P;
Next(P) = First(L);
Prev(P) = First(L);
Last(L) = First(L);
}
else
{
Next(P) = First(L);
Prev(P) = Last(L);
Next(Last(L)) = P;
Prev(First(L)) = P;
Last(L) = P;
}
}
void insertAfter(List &L, address P, address Prec)
{
if(First(L) == NULL)
{
insertFirst(L,P);
}
else
{
Next(P) = Next(Prec);
Next(Prec) = P;
}
}
void deleteFirst(List &L, address &P)
{
P = First(L);
First(L) = Next(P);
Next(P) = NULL;
}
void deleteLast(List &L, address &P)
{
if(Next(First(L)) == NULL)
{
deleteFirst(L,P);
}
else
{
address Q = First(L);
while(Next(Next(Q)) != NULL)
{
Q = Next(Q);
}
P = Next(Q);
Next(Q) = NULL;
}
}
void deleteAfter(List &L, address &P, address &Prec)
{
P = Next(Prec);
Next(Prec) = Next(P);
Next(P) = NULL;
}
address findElm(List L, infotype x){
address Q = First(L);
while(Q != NULL){
if(Info(Q).ID == x.ID){
return Q;
}
Q = Next(Q);
}
return NULL;
}