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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
PROGRAM test;
{
A small test of linklist unit.
nils.sjoholm@mailbox.swipnet.se
}
uses
{$ifdef Amiga}
exec,
{$endif}
linklist, strings;
VAR
Mylist : pList;
MyNode : pFPCNode;
i : Longint;
temp : Longint;
buffer : PChar;
bufsize : Longint;
templist : pList;
BEGIN
CreateList(Mylist);
AddNewNode(Mylist,'Monday');
AddNewNode(Mylist,'Tuesday');
AddNewNode(Mylist,'Wednesday');
AddNewNode(Mylist,'Thursday');
AddNewNode(Mylist,'Friday');
AddNewNode(Mylist,'Saterday');
AddNewNode(Mylist,'Sunday');
writeln;
WriteLN('This is the list');
PrintList(Mylist);
writeln;
WriteLN('Now we are going to remove the last node');
WriteLN('>> Press return');
readln;
RemoveLastNode(Mylist);
PrintList(Mylist);
writeln;
WriteLN('>> Press return to get the size of the list');
writeln;
readln;
WriteLN('The size of allocated list is ', SizeOfList(Mylist));
writeln;
writeln('Now we are going to print all strings' +#10+ 'in the list with the internal commands');
WriteLN('>> Press return');
readln;
i := NodesInList(Mylist);
MyNode := GetFirstNode(Mylist);
FOR temp := 1 TO i DO BEGIN
WriteLN(MyNode^.ln_Name);
MyNode := GetNextNode(MyNode);
END;
writeln;
WriteLN('We will move the last node to the top');
WriteLN('>> Press return');
readln;
MyNode := GetLastNode(Mylist);
MoveNodeTop(Mylist,MyNode);
PrintList(Mylist);
writeln;
WriteLN('We shall change the value in one node');
WriteLN('>> Press return');
readln;
MyNode := GetFirstNode(Mylist);
MyNode := GetNextNode(MyNode);
UpDateNode(MyNode,'This is the new day');
PrintList(Mylist);
writeln;
MyNode := GetNextNode(MyNode);
WriteLN('Now we delete one node');
WriteLN('>> Press return');
readln;
WriteLN('This node is going to be deleted ',GetNodeData(MyNode));
DeleteNode(MyNode);
PrintList(Mylist);
writeln;
WriteLN('Sort the list');
WriteLN('>> Press return');
readln;
SortList(Mylist);
PrintList(Mylist);
writeln;
writeln('Search for a node, in this case Friday');
WriteLN('>> Press return');
readln;
MyNode := FindNodeData(Mylist,'Friday');
IF MyNode <> NIL THEN BEGIN
WriteLN('found the node ',MyNode^.ln_Name);
{ or writeln('found the node ',GetNodeData(MyNode)); }
END ELSE BEGIN
WriteLN('Node not found');
END;
writeln;
WriteLN('And now copy the list to a stringbuffer' +#10+ 'and print it');
WriteLN('>> Press return');
readln;
bufsize := SizeOfList(Mylist);
buffer := StrAlloc(bufsize);
ListToBuffer(Mylist,buffer);
WriteLN(buffer);
writeln;
WriteLN('Now we try to copy the list to a new list');
WriteLN('>> Press return');
readln;
templist := CopyList(Mylist);
IF templist <> NIL THEN BEGIN
WriteLN('That went well, the new list is here');
PrintList(templist);
DestroyList(templist);
END ELSE BEGIN
WriteLN('no copy of list');
END;
writeln;
WriteLN('Press return to destroy the list');
readln;
DestroyList(Mylist);
writeln;
WriteLN('All done');
END.
|