Algorithme de liste chainée
Salut
J'ai un problème de tri de la liste chaînée.
Comment créer un programme permettant de trier par ordre alphabétique une liste chaînée ?
Voilà mon code :
Code:
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
| program lust;
uses wincrt;
type
pointeur=^per;
per=record
s:string;
svt:pointeur;
end;
var debut,courant,t:pointeur;
i:integer ;
rep:char;
s,p:string;
procedure aff (s:string);
begin
courant:=debut;
while courant <>nil do
begin
writeln (courant^.s);
courant:=courant^.svt;
end;
end;
begin
new (debut);
courant:=debut;
repeat
write ('donne le mot: ');
readln(courant^.s);
write (' outre siesie:o\n ? ');
readln (rep);
if rep='o' then
begin
new(courant^.svt);
courant:=(courant^.svt);
end
else
courant^.svt:=nil ;
until rep='n';
aff (s);
courant:=debut;
while courant<>nil do
begin
if courant^.s<courant^.svt^.s then
begin
p:=courant^.s;
courant^.s:=courant^.svt^.s;
courant^.svt^.s:=p;
end
else
courant:=courant^.svt;
end;
aff (s);
end. |
Merci à tous.