Advertisement
apfel2kuchen

Bäumlein

Feb 13th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. program einlesenBaum (input, output);
  2. type
  3. tRefBinBaum = ^tBinBaum;
  4. tBinBaum = Record
  5. Info : integer;
  6. Links : tRefBinBaum;
  7. Rechts : tRefBinBaum;
  8. end;
  9.  
  10. var
  11. Wurzel : tRefBinBaum;
  12. NewSohn : tRefBinBaum;
  13. Zeiger : tRefBinBaum;
  14. Eingabe : integer;
  15. Eingefugt : boolean;
  16.  
  17. begin
  18. wurzel := NIL;
  19. write ('Wurzel Wert: ');
  20. readln (Eingabe);
  21. while (Eingabe <> 0) do
  22. begin
  23. Zeiger := wurzel;
  24. writeln ('Drinnen');
  25. if wurzel = nil then
  26. begin
  27. new (wurzel);
  28. Wurzel^.Info := Eingabe;
  29. Wurzel^.Links := NIL;
  30. Wurzel^.Rechts := NIL;
  31. writeln ('Drinnen');
  32. end
  33. else
  34. begin
  35. writeln ('IN ELSE');
  36. new (newSohn);
  37. NewSohn^.Info := Eingabe;
  38. NewSohn^.Rechts := NIL;
  39. NewSohn^.Links := NIL;
  40. {Nun An der richtigen Stelle einfügen}
  41. if Wurzel^.Info < NewSohn^.Info then
  42. begin
  43. if Wurzel^.Rechts = NIL then
  44. Wurzel^.Rechts := NewSohn;
  45. else
  46. begin
  47.  
  48. end; {Einfügen}
  49. end;
  50. Zeiger := NewSohn;
  51.  
  52. writeln (wurzel^.links^.info,'NEW SOHN DONE');
  53. end; {Neuer Wert wurde eingefügt}
  54. Write ('Geben Sie den Naechsten Wert ein: ');
  55. Readln (Eingabe);
  56. end; {WHILE EINGABE = 0 ENDE}
  57.  
  58. Writeln ('Wurzel: ', Wurzel^.Info, ' | Rechts: ',Wurzel^.Rechts^.Info, ' | Links: ', Wurzel^.links^.Info)
  59. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement