-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer_queue.pas
More file actions
131 lines (109 loc) · 2.24 KB
/
Copy pathpointer_queue.pas
File metadata and controls
131 lines (109 loc) · 2.24 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
program pointer_queue;
uses crt;
type
TInfo = integer;
TNode = ^TElement;
TElement = record
data : TInfo;
next : TNode;
end;
var option : byte;
num : TInfo;
num_queue : TElement;
procedure ReadInfo(var info : TInfo);
begin
clrscr;
write('Insert the info: ');
read(info);
end;
procedure CreateQueue(var queue : TNode);
begin
queue := nil;
end;
procedure Include(var queue : TNode; info : TInfo);
var aux, aux2 : TNode;
begin
new(aux);
if aux = nil then
begin
write('Memory full!');
readkey;
end
else if queue = nil then
begin
aux^.data := info;
aux^.next := nil;
queue := aux;
end
else begin
aux2 := queue;
while aux2^.next <> nil do
begin
aux2 := aux2^.next;
end;
aux^.data := info;
aux^.next := nil;
aux2^.next := aux;
end;
end;
procedure Remove(var queue : TNode);
var aux : TNode;
begin
if queue = nil then
begin
write('Memory full!');
readkey;
end else
begin
aux := queue;
writeln('Element ', aux^.data, ' removed!');
queue := aux^.next;
dispose(aux);
readkey;
end;
end;
function CountElements(var queue : TNode) : byte;
var aux : TNode;
i : byte;
begin
i := 0;
if queue <> nil then
begin
aux := queue;
while aux <> nil do
begin
i := i + 1;
writeln(i, ' - ', aux^.data);
aux := aux^.next;
end
end;
CountElements := i;
end;
begin
option := 1;
CreateQueue(num_queue);
while option <> 0 do
begin
clrscr;
writeln ('0 - Exit');
writeln ('1 - Include');
writeln ('2 - Remove');
writeln ('3 - Count elements');
readln (option);
writeln;
case option of
1:
begin
ReadInfo(num);
Include(num_queue, num);
end;
2:
begin
Remove(num_queue);
end;
3:
begin
writeln(CountElements(num_queue), ' elements');
readkey;
end;
end.