program lab9;
uses crt;
type
Link = ^List;
List = record
next: Link;
data: string;
NumRand: integer;
end;
var
i:integer;
TopElement: Link;
tocase:byte;
doexit:boolean;
function DataAsk : string;
begin
Write('Vedit dani:');
Readln(DataAsk);
end;
procedure DataCreate(pdata:string);
begin
TopElement:=New(Link);
TopElement^.data := pdata;
TopElement^.NumRand := Random(10000);
TopElement^.next := nil;
end;
procedure DataAdd(pdata:string);
var temp: Link;
begin
temp := new(Link);
temp^.data := pdata;
temp^.NumRand := Random(10000);
temp^.next := TopElement;
TopElement := temp;
end;
procedure DataDel;
var temp: Link;
begin
temp := TopElement;
if temp^.next=nil then
begin
writeln('Stek pustij.');
TopElement := nil
end
else
begin
temp := temp^.next;
TopElement := temp;
end;
end;
procedure Show;
var temp : Link;
begin
temp := TopElement;
while temp <> nil do
begin
writeln('Dani: ', temp^.data, ' - ', temp^.NumRand);
temp:=temp^.next;
end;
end;
procedure ShowNData;
var temp : Link;
n : word;
begin
write('Veditj №: ');
readln(n);
temp := TopElement;
for i:=1 to n do
begin
if i=n then writeln('Dani: ', temp^.data, ' - ', temp^.NumRand);
if temp=nil then
begin
writeln('Ne znajdeno poziciji №: ', n);
break;
end;
temp:=temp^.next;
end;
end;
procedure Search;
var temp : Link;
stext: string;
isfind : boolean;
begin
write('Veditj wukanij tekst: ');
readln(stext);
temp := TopElement;
while temp <> nil do
begin
if temp^.data=stext then
begin
writeln('Znajdeno: ', temp^.data, ' - ', temp^.NumRand);
isfind := true;
end;
temp:=temp^.next;
end;
if isfind <> true then writeln('Zapys (', stext ,') ne znajdeno.');
end;
begin
repeat
clrscr;
writeln('Oberitj diu');
writeln;
writeln('1.Novij zapys.');
writeln('2.Dodaty zapys.');
writeln('3.Vydalyty.');
writeln('4.Vyvesty zapys novyj.');
writeln('5.Vyvesty vsi dani.');
writeln('6.Powuk.');
writeln;
writeln('0.Vyjty.');
writeln;
write('Vykonaty diu nomer: ');
readln(tocase);
case tocase of
1:DataCreate(DataAsk);
2:DataAdd(DataAsk);
3:DataDel;
4:ShowNData;
5:Show;
6:Search;
0:doexit:=true
else writeln('Pomylka!')
end;
writeln('Diu ', tocase,' vykonano. Enter - prodov*yty');
readln;
until doexit;
end.
Динамические структуры данных, Нужно переделать в стек... |