Всем привет.Нужно создать список и уметь его редактировать.
Pascal |
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
| program two;
uses CRT;
const
norm=$17;
sel=$70;
N=5;
type
one=^Tspisok;
Tspisok=object
head:one;
inf:string;
next:one;
procedure DelData;
procedure addData(info:string);
procedure printData;
procedure seData;
{procedure DelData(info:string);}
end;
procedure Tspisok.seData;
var cur:one;s:string;
begin
readln(s);
cur:=head;
while (cur<>nil) and (cur^.inf<>s) do
cur:=cur^.next;
if cur^.inf=s then writeln(cur^.inf);
end;
procedure Tspisok.addData(info:string);
var
cur:one;
begin
clrscr;
new(cur);
cur^.inf:=info;
cur^.next:=head;
head:=cur;
end;
procedure Tspisok.printData;
var
cur:one;
begin
cur:=head;
while cur<>nil do
begin
writeln(cur^.inf);
cur:=cur^.next
end;
end;
procedure Tspisok.DelData;
var cur,pred:one;Idel:string;
begin
clrscr;
writeln('Enter del data:');
cur:=head;
readln(Idel);
while (cur<>nil) and (cur^.inf<>Idel) do
cur:=cur^.next;
if cur^.inf=Idel then
begin
cur:=Pred^.next;
Pred^.next:=Pred^.next^.next;
{Idel:=cur^.inf; }
writeln('Del data:',cur^.inf);
dispose(cur);{<= Ругаеться матом #204 - указатель пуст или указывает не на кучу}
end;
readln;
end;
{var
cur:one;
begin
cur:=head;
head:=head^.next;
info:=cur^.inf;
dispose(cur);
end; }
var
i:word;
data:string;
obj:Tspisok;
menu:array[1..N] of string[20];
punkt:integer;
ch:char;
x,y:integer;
Procedure MenuToScr;
var i:integer;
begin
ClrScr;
for i:=1 to N do begin
GoToXY(x,y+i-1);
write(menu[i]);
end;
TextAttr:=SEL;
GoToXY(x,y+punkt-1);
write(menu[punkt]);
TextAttr:=NORM;
end;
begin
menu[1]:=' Add your data ';
menu[2]:=' Print your data ';
menu[3]:=' Del data ';
menu[4]:=' Exit ';
menu[5]:='s';
punkt:=1;
x:=5;
y:=5; TextAttr:=NORM;
MenuToScr;
repeat
ch:=ReadKey;
if ch=char(0) then begin
ch:=ReadKey;
case ch of
chr(80):
if punkt<N then begin
GoToXY(x,y+punkt-1);
write(menu[punkt]);
punkt:=punkt+1;
TextAttr:=SEl;
GoToXY(x,y+punkt-1);
write(menu[punkt]);
TextAttr:=NORM;
end;
chr(72):
if punkt>1 then begin
GoToXY(x,y+punkt-1);
write(menu[punkt]);
punkt:=punkt-1;
TextAttr:=SEl;
GoToXY(x,y+punkt-1);
write(menu[punkt]);
TextAttr:=NORM;
end;
end;
end
else
if ch=chr(13) then begin
case punkt of
1:begin
clrscr;
writeln('Add your data: ');
readln(data);
obj.adddata(data);
end;
2:begin
clrscr;
writeln('Your data: ');
obj.printdata;
readln;
end;
3:begin
clrscr;
obj.deldata;
end;
4:ch:=chr(27);
5:begin
clrscr;
obj.seData;
readln;
end;
end;
MenuToScr;
end;
until ch=chr(27);
end. |
|
В самом конце процедурки Deldata ругаеться, что мол либо указатель пуст, либо указывает на элемент вне кучи. Но у меня то он указывает на поле Inf => по идеи должен уничтожать его.И вообще мне не понятно как вставлять\удалять в произвольное место списка элементы, объясните пожалуйста.
Вот процедура, в кторой ошибка:
Pascal |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| procedure Tspisok.DelData;
var cur,pred:one;Idel:string;
begin
clrscr;
writeln('Enter del data:');
cur:=head;
readln(Idel);
while (cur<>nil) and (cur^.inf<>Idel) do
cur:=cur^.next;
if cur^.inf=Idel then
begin
cur:=Pred^.next;
Pred^.next:=Pred^.next^.next;
Idel:=cur^.inf;
writeln('Del data:',cur^.inf);
dispose(cur);{Вот тут Ошибка 204}
end;
readln;
end; |
|