Hi Jungs!
Der folgende Teil sortiert eine verkettete Liste absteigend:
Delphi-Quellcode:
...
repeat
changed := false;
prev_node := nil;
curr_node := start;
while assigned(curr_node.next) do
begin
next_node := curr_node.next;
if curr_node.zahl < next_node.zahl then
begin
curr_node.next := next_node.next;
next_node.next := curr_node;
if prev_node <> nil
then prev_node.next := next_node;
if curr_node = start
then start := next_node;
changed := true;
prev_node := next_node;
end
else
begin
prev_node := curr_node;
curr_node := curr_node.next;
end;
end;
until (not changed) and (curr_node.next = nil);
...
und dazu ein paar Deklarationen:
Delphi-Quellcode:
type
...
PNode = ^TNode;
TNode = record
next: PNode;
zahl: integer;
end;
...
var
...
start: PNode;
prev_node: PNode;
curr_node: PNode;
next_node: PNode;
...
Viele Grüße
Markus