Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program merge (input, output);
- { liest ohne Eingabeueberpruefung zwei sortierte Felder mit
- integer-Zahlen ein; beide Felder werden in Feld sortiert
- zusammengefuegt; das Ergebnis wird ausgegeben; ist die Ein-
- gabe unsortiert, so ist das Ergebnisfeld nicht sortiert }
- const
- GRENZE1 = 5;
- GRENZE2 = 8;
- GRENZE = 13; { GRENZE1 + GRENZE2 }
- GRENZE1PLUS1 = 6;
- GRENZE2PLUS1 = 9;
- GRENZEPLUS1 = 14;
- type
- tIndex1 = 1..GRENZE1;
- tIndex2 = 1..GRENZE2;
- tIndex = 1..GRENZE;
- tIndex1Plus1 = 1..GRENZE1PLUS1;
- tIndex2Plus1 = 1..GRENZE2PLUS1;
- tIndexPlus1 = 1..GRENZEPLUS1;
- tFeld1 = array [tIndex1] of integer;
- tFeld2 = array [tIndex2] of integer;
- tFeld = array [tIndex] of integer;
- var
- Feld1 : tFeld1;
- Feld2 : tFeld2;
- Feld : tFeld;
- i : tIndex1Plus1;
- j : tIndex2Plus1;
- k : tIndexPlus1;
- {EVTL WEITERE VARIABLEN}
- begin
- { sortierte Felder einlesen }
- writeln ('Bitte', GRENZE1:2, ' Werte des ersten Feldes ',
- 'sortiert eingeben!');
- for i := 1 to GRENZE1 do
- readln (Feld1[i]);
- writeln ('Bitte', GRENZE2:2, ' Werte des zweiten Feldes ',
- 'sortiert eingeben!');
- for j := 1 to GRENZE2 do
- readln (Feld2[j]);
- {Sortieren der Arrays über eine While Schleife}
- i := 1;
- j := 1;
- for k := 1 to grenze do
- {Pruefe feld1 < feld2 und ob Grenze1 Überschritten ist wenn ja else}
- begin
- if (i<=GRENZE1) and (feld1[i] <= feld2[j]) then
- begin
- feld[k] := feld1[i];
- i := i + 1;
- writeln ('Wert von i', i);
- end
- else if (j<=GRENZE2) and (feld2[j] <= feld1[i]) then
- begin
- feld[k] := feld2[j];
- j := j + 1;
- writeln ('Wert von j', j);
- end
- else if (i > GRENZE1) then
- begin
- feld[k] := feld2[j];
- j := j + 1;
- writeln ('YEAHH Wert von j', j)
- end
- else if (j > GRENZE2) then
- begin
- feld[k] := feld2[i];
- i := i + 1;
- writeln ('YEAHH Wert von i', i)
- end;
- end;
- writeln ('Das Ergebnisfeld ist:');
- for k := 1 to GRENZE do
- write (Feld[k]:8);
- writeln
- end. { merge }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement