donc j'ai cet énorme tas de code, mais ça ne marchera pas correctement. Et je ne suis pas sûr de la façon dont une liste fonctionne exactement. Quelqu'un peut-il m'indiquer à la bonne direction qui est bon à cela? MERCI BEAUCOUP :)Pourquoi ma liste à double liaison ne fonctionne-t-elle pas? (Pascal)
Program ListendDerHoelle;
Uses CRT;
TYPE
Pokemon = ^pointer;
pointer =
RECORD
PokemonName : STRING[30];
PokemonPosition : INTEGER;
Next : Pokemon;
Prev : Pokemon;
END;
VAR Liste, Eintrag, head: Pokemon;
FUNCTION TraverseList(AddPokemonPosition : INTEGER) : Boolean; FORWARD;
PROCEDURE Ausgabe(i: Integer); FORWARD;
PROCEDURE Abfrage;
VAR PokemonName2 : STRING[30];
PokemonPosition2, Anzahl, i : Integer;
BEGIN
Liste := NIL;
Eintrag := NIL;
Anzahl := 99;
Writeln('Wie viele Pokemon einspeichern?');
Writeln;
Readln(Anzahl);
FOR i := 1 TO Anzahl DO
BEGIN
ClrScr;
Writeln('Pokemon Name:');
Writeln;
Readln(PokemonName2);
ClrScr;
Writeln('Pokemon Position:');
Writeln;
Readln(PokemonPosition2);
ClrScr;
New(Eintrag);
Eintrag^.Next := NIL;
Eintrag^.Prev := NIL;
IF TraverseList(PokemonPosition2) = TRUE THEN
BEGIN
Eintrag^.PokemonName := PokemonName2;
Eintrag^.PokemonPosition := PokemonPosition2;
Liste := Eintrag;
END
ELSE
BEGIN
Writeln('Position nicht gefunden. Das Ende der Welt steht unmittelbar bevor!');
END;
END;
Ausgabe(Anzahl);
END;
FUNCTION TraverseList(AddPokemonPosition : INTEGER) : Boolean; // Wenn die Funktion also True zurückgibt, ist das Element gefunden!
VAR vElementFound : Boolean;
BEGIN
vElementFound := FALSE;
TraverseList := FALSE;
WHILE (vElementFound = FALSE) DO
BEGIN
IF (Liste = NIL) THEN // wenn es das erste Element ist
BEGIN
vElementFound := TRUE;
Head := Liste;
END
ELSE IF ((Liste^.Next = NIL) AND (vElementFound = FALSE)) THEN // wenn es das letzte Element ist
BEGIN
Liste := Liste^.Next;
vElementFound := TRUE;
END
ELSE IF (vElementFound = FALSE) THEN // ansonsten
BEGIN
IF (Eintrag^.PokemonPosition < AddPokemonPosition) AND NOT (Eintrag^.Next^.PokemonPosition > AddPokemonPosition) THEN
BEGIN
Liste := Liste^.Next;
END
ELSE IF (Eintrag^.PokemonPosition > AddPokemonPosition) AND NOT (Eintrag^.Prev^.PokemonPosition > AddPokemonPosition) THEN
BEGIN
Liste := Liste^.Prev;
END
ELSE
BEGIN
vElementFound := TRUE;
END;
END;
END;
IF (vElementFound = TRUE) THEN
BEGIN
TraverseList := TRUE;
END;
END;
PROCEDURE Ausgabe(i : Integer);
var a : Integer;
BEGIN
Liste := Head;
FOR a := 1 TO i DO BEGIN
Writeln(Eintrag^.PokemonName, ' ', Eintrag^.PokemonPosition);
Liste := Liste^.Next;
Readkey;
end;
END;
BEGIN
Abfrage();
END.
ignorer la partie terminale, je sais que ce produit habitude les bons résultats encore, juste la fonction « traverselist » est intéressant
votre liste est prioritaire à chaque itération n'est-ce pas? – Emiliano