Reja: Ro’yxat dinamik strukturasi


Download 42.23 Kb.
bet3/4
Sana27.01.2023
Hajmi42.23 Kb.
#1133465
1   2   3   4
Bog'liq
3-mavzu Ro\'yxatlar va ko\'rsatkich tuzilmalari

head^.next^.key ifоdаsi ro’yхаtning birinchi elеmеntini, head^. Next^.next^.key – esа ikkinchi elеmеntini bеrаdi.
Quyidа аvtоmоbillаr to’g’risidаgi mа’lumоtlаrni qаytа ishlоvchi dаstur mаtnini kеltirаmiz:
program car;
uses
crt;
type namestr = string[20];
Link = ^Node;
Node = record
name: namestr;
speed: integer;
next: link;
end;
var head, z: link;
namfind: namestr;
v: 0..4;
endmenu: boolean;
procedure list_initialize;
begin
new(head);
new(z);
head^.next:=z;
z^.next:=nil;
end;
procedure list_destroy;
begin
dispose(head);
dispose(z);
end;
procedure insert_after(name1: namestr; speed1: integer; t: link);
var x : link;
begin
new(x);
x^.name := name1;
x^.speed:= speed1;
x^.next := t^.next;
t^.next := x;
end;
procedure delete_next(t: link);
var
del: link;
begin
del := t^.next;
t^.next := t^.next^.next;
dispose(del);
end;
procedure InpAuto;
var
nam: namestr;
sp: integer;
begin
write('Avtоmоbil markasini kiriting: ');
readln(nam);
write('Mаksimаl tezlik: ');
readln(sp);
insert_after(nam, sp, head);
end;
procedure Mylist;
var
Curr: Link;
begin
Curr:=head^.next;
While Curr^.next <> nil do
begin
writeln('Mаrkа: ', Curr^.name, ' Tezlik: ', Curr^.Speed);
curr:=curr^.next;
end;
write('Enterni bosing');
readln;
end;
function findname(fn: namestr): link;
var
Curr: Link;
begin
Curr:=head;
While Curr<>Nil do
if Curr^.name=fn then
begin
findname:=curr;
exit;
end
else
curr:=curr^.next;
findName:=Nil;
end;
begin
list_initialize;
endmenu:=false;
repeat
clrscr;
writeln(' Ishlardan biri tanlansin:');
writeln('1.Ro’yxatga birinch yuzish');
writeln('2. Ro’yxatdagi birinchi elementni o’chirish');
writeln('3. Butun ro’yxatni ko’rish');
writeln('4. Tanlangan elementdan keyingisini o’chirish’);
writeln('0. Ishni tugatish');
readln(v);
case v of
1: inpauto;
2: delete_next(head);
3: mylist;
4: begin
writeln('Ro’yxatdan o’chiriladigan elementdan oldin keluvchi avtomobil markasi kiritilsin');
readln(NamFind);
delete_next(FindName(namfind));
end;
else
endmenu:=true;
end;
until endmenu;
list_destroy;
end.
end;

Download 42.23 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling