Advertisement
apfel2kuchen

Untitled

Oct 24th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. program merge (input, output);
  2. { liest ohne Eingabeueberpruefung zwei sortierte Felder mit
  3. integer-Zahlen ein; beide Felder werden in Feld sortiert
  4. zusammengefuegt; das Ergebnis wird ausgegeben; ist die Ein-
  5. gabe unsortiert, so ist das Ergebnisfeld nicht sortiert }
  6. const
  7. GRENZE1 = 5;
  8. GRENZE2 = 8;
  9. GRENZE = 13; { GRENZE1 + GRENZE2 }
  10. GRENZE1PLUS1 = 6;
  11. GRENZE2PLUS1 = 9;
  12. GRENZEPLUS1 = 14;
  13.  
  14. type
  15. tIndex1 = 1..GRENZE1;
  16. tIndex2 = 1..GRENZE2;
  17. tIndex = 1..GRENZE;
  18. tIndex1Plus1 = 1..GRENZE1PLUS1;
  19. tIndex2Plus1 = 1..GRENZE2PLUS1;
  20. tIndexPlus1 = 1..GRENZEPLUS1;
  21. tFeld1 = array [tIndex1] of integer;
  22. tFeld2 = array [tIndex2] of integer;
  23. tFeld = array [tIndex] of integer;
  24.  
  25. var
  26. Feld1 : tFeld1;
  27. Feld2 : tFeld2;
  28. Feld : tFeld;
  29. i : tIndex1Plus1;
  30. j : tIndex2Plus1;
  31. k : tIndexPlus1;
  32.  
  33. {EVTL WEITERE VARIABLEN}
  34. begin
  35. { sortierte Felder einlesen }
  36. writeln ('Bitte', GRENZE1:2, ' Werte des ersten Feldes ',
  37. 'sortiert eingeben!');
  38. for i := 1 to GRENZE1 do
  39. readln (Feld1[i]);
  40. writeln ('Bitte', GRENZE2:2, ' Werte des zweiten Feldes ',
  41. 'sortiert eingeben!');
  42. for j := 1 to GRENZE2 do
  43. readln (Feld2[j]);
  44.  
  45.  
  46. {Sortieren der Arrays über eine While Schleife}
  47. i := 1;
  48. j := 1;
  49.  
  50. for k := 1 to grenze do
  51. {Pruefe feld1 < feld2 und ob Grenze1 Überschritten ist wenn ja else}
  52. begin
  53. if (i<=GRENZE1) and (feld1[i] <= feld2[j]) then
  54. begin
  55. feld[k] := feld1[i];
  56. i := i + 1;
  57. writeln ('Wert von i', i);
  58. end
  59. else if (j<=GRENZE2) and (feld2[j] <= feld1[i]) then
  60. begin
  61. feld[k] := feld2[j];
  62. j := j + 1;
  63. writeln ('Wert von j', j);
  64. end
  65. else if (i > GRENZE1) then
  66. begin
  67. feld[k] := feld2[j];
  68. j := j + 1;
  69. writeln ('YEAHH Wert von j', j)
  70. end
  71. else if (j > GRENZE2) then
  72. begin
  73. feld[k] := feld2[i];
  74. i := i + 1;
  75. writeln ('YEAHH Wert von i', i)
  76. end;
  77.  
  78. end;
  79.  
  80. writeln ('Das Ergebnisfeld ist:');
  81. for k := 1 to GRENZE do
  82. write (Feld[k]:8);
  83. writeln
  84. end. { merge }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement