Tu zadam prostsze pytanie.
Ma ktos procedure sortowania (obojetnie jaka metoda) na liscie dwukierunkowej:
Tu zadam prostsze pytanie.
Ma ktos procedure sortowania (obojetnie jaka metoda) na liscie dwukierunkowej:
up
prosze bardzo :)))
--------------------------------
program onlysort2;
{$APPTYPE CONSOLE}
uses
SysUtils;
Type
PElement2 = ^TElement2;
TElement2 = record
dane:integer;
next:PElement2;
prev:PElement2
End;
Zbior=0..10;
Var
root2,last2 : PElement2;
count : Integer;
decyzja : Zbior;
Procedure Genrerate_list_2(count:integer);
Var
n : integer;
newone : PElement2;
Begin
Randomize;
root2:=NIL;
last2:=NIL;
For n:=1 To count Do
Begin
new(newone);
newone^.next:=NIL;
newone^.prev:=NIL;
newone^.dane:=random(100);
if root2 = NIL then
Begin
root2:=newone;
last2:=root2;
End{if}
Else
Begin
newone^.prev:=last2;
last2^.next:=newone;
last2:=newone;
End;{else}
End;
End;
Procedure wyswiet_liste_root(root:PElement2);
Var
actList:PElement2;
Begin
Writeln;
Writeln(' Lista ma postac:');
actList:=root2;
While actList<>NIL Do
Begin
Write(' ',(actList^.dane));
actList:=actList^.Next;
End;
Writeln;
End;
Procedure Destroy_lista_2;
Var
ToDelete:PElement2;
Begin
While root2<>NIL Do
Begin
ToDelete:=root2;
root2:=root2^.next;
dispose(ToDelete);
End;
End;
procedure zamien(var root2, last2, ActList: PElement2);
var
temp, PrevAt: PElement2;
begin
if ActList^.next <> nil then
begin
if ActList <> root2 then
begin
temp := ActList^.next;
PrevAt := ActList^.prev;
ActList^.next := temp^.next;
if temp^.next <> nil then
temp^.next^.prev := ActList;
PrevAt^.next := temp;
temp^.prev := PrevAt;
temp^.next := ActList;
ActList^.prev := temp;
end
else
begin
temp := ActList^.next;
ActList^.next := temp^.next;
if temp^.next <> nil then
temp^.next^.prev := ActList;
temp^.next := ActList;
ActList^.prev := temp;
temp^.prev := nil;
root2 := temp;
end;
if temp = last2 then
last2 := ActList;
ActList := temp;
end;
end;
procedure Sortuj2(var root2, last2: PElement2);
var
ActList: PElement2;
zrobione: boolean;
begin
zrobione := True;
while zrobione do
begin
zrobione := False;
ActList := root2;
if ActList <> nil then
while ActList <> last2 do
begin
if ActList^.dane > ActList^.next^.dane then
begin
zamien(root2, last2, ActList);
zrobione := True;
end;
ActList := ActList^.next;
end;
end;
end;
Procedure nowa;
Begin
Destroy_lista_2;
Writeln('Podaj liczbe elementow');
Readln(count);
If count<=0 Then exit;
Genrerate_list_2(count);
wyswiet_liste_root(root2);
End;
BEGIN
clrscr;
Writeln('Podaj liczbe elementow');
Readln(count);
If count<=0 Then exit;
Genrerate_list_2(count);
Repeat
clrscr;
wyswiet_liste_root(root2);
Writeln;
Writeln('Menu: 0 : EXIT 1: Rozpocznij sortowanie 2 : Nowa lista ');
Readln(decyzja);
Case decyzja of
0 : Exit;
1 : sortuj2(root2,last2);
2 : nowa
End;
Until false;
Destroy_lista_2;
END.
muczos gracjas ;D