-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary_tree_minimum_and_minimumnode.pas
More file actions
72 lines (72 loc) · 1.14 KB
/
Binary_tree_minimum_and_minimumnode.pas
File metadata and controls
72 lines (72 loc) · 1.14 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
program minimum_and_minimumnode;
type
tree = ^node;
node = record
data:integer;
cl:tree;
cr:tree;
end;
procedure add(var a:tree;n:integer);
begin
if (t = nil) then
begin
new(t);
t^.data:=n;
t^.cl:=nil;
t^.cr:=nil;
end
else
begin
if (t^.data<=n) then
add(t^.cl,n);
else
add(t^.cr,n);
end;
end;
procedure chargetree(abb:tree;num:integer);
begin
writeln('write some number: (50 stop the process)');
readln(num);
while (num<>50) do
begin
add(abb,num);
writeln('write some number: (50 stop the process)');
readln(num);
end;
end;
function minimum (t:tree):integer;
begin
if (t<>nil) then
begin
if (t^.cl=nil) then
minimum:= t^.data;
else
minimum:= minimum(t^.cl,minimum);
end;
end;
function minimumnode(t:tree):tree;
begin
if (t<>nil) then
begin
if (t=nil) then
minimumnode:= nil;
else
begin
if (t^.cl=nil) then
minimumnode:= t;
else
minimumnode:= minimumnode(t^.cl,mininimumnode);
end;
end;
end;
var
tr,minimnode:tree;
minim,num:integer;
begin
tr:=nil;
chargetree(tr,num);
minim:=minimum(tr);
minimnode:=minimumnode(tr);
writeln(minim);
writeln(minimnode);
end.