Delphi |
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
| type
Stack = ^TStack;
TStack = record
key : integer;
next : Stack;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
Button4: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
s : Stack;
implementation
{$R *.dfm}
function Empty(s : stack) : boolean;
begin
if s = nil then Empty := true
else Empty := false;
end;
procedure push(var s : stack; key : integer);
var p : stack;
begin
new(p);
p^.key:= key;
p^.next := s;
s := p;
end;
procedure pop(var s : stack);
var p : stack;
begin
if not Empty(s) then begin
p := s;
s := s^.next;
dispose(p);
end
else
ShowMessage('Stack is empty');
end;
function top(s : stack) : integer;
begin
if not Empty(s) then begin
top := s^.key;
end
else
ShowMessage('Stack is empty');
end;
function Count(s : stack) : integer;
var coun : integer;
begin
coun := 0;
while not Empty(s) do begin
s := s^.next;
coun := coun + 1;
end;
Count := coun;
end;
procedure PrintS(s : stack);
begin
Form1.Edit1.Text := '';
if Empty(s) then ShowMessage('Stack is empty')
else
while not Empty(s) do begin
Form1.Edit1.Text := Form1.Edit1.Text + IntToStr(s^.key) + ' ';
s := s^.next;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var filename : string;
buf : string;
ch : char;
f: textfile;
begin
s := nil;
if OpenDialog1.Execute then filename := OpenDialog1.FileName;
reset(f, filename);
while not eof(f) do begin
buf := '';
while (not eof(f)) and (ch in ['0'..'9']) do begin
if (ch in ['0'..'9']) then buf := buf + ch;
read(f, ch);
end;
if (not eof(f))and (buf <>'') then push(s, StrToInt(buf));
while (not eof(f)) and (not (ch in ['0'..'9'])) do
read(f, ch);
end;
closefile(f);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PrintS(s);
end;
procedure TForm1.Button3Click(Sender: TObject);
var k: integer;
begin
Edit1.Text := '';
//Edit1.Text := IntToStr(top(s));
pop(s);
end;
procedure TForm1.Button4Click(Sender: TObject);
var k: integer;
str: string;
begin
k := Count(s);
str := IntToStr(Count(s));
ShowMessage('Stack size : ' + str);
end;
end. |
|
Этот код компилируется без ошибок и работает как должен. Но если В событии TForm1.Button3Click раскомментировать Edit1.Text := IntToStr(top(s)); появляется ошибка Missing operator or semicolon.
Помогите! Что не так?