Type TElement = Packed Record Name: String; End; Var Tab: Array[0..3] of TElement;
Procedure Display; Var E: TElement; Begin For E in Tab Do Writeln('--> ', E.Name); Writeln; End;
Procedure Sort; Var I, J: low(Tab)..high(Tab); Tmp : TElement;
Procedure Swap(Cond: Boolean); Begin if (Cond) Then Begin Tmp := Tab[J]; Tab[J] := Tab[J+1]; Tab[J+1] := Tmp; End; End; Begin For I := high(Tab) Downto low(Tab) Do For J := low(Tab) To I Do if (I <> J) Then Swap((Length(Tab[J].Name)> Length(Tab[J+1].Name))); End;
Proszę:
http://pastebin.com/JN9TmGBQ
Type TElement = Packed Record
Name: String;
End;
Var Tab: Array[0..3] of TElement;
Procedure Display;
Var E: TElement;
Begin
For E in Tab Do
Writeln('--> ', E.Name);
Writeln;
End;
Procedure Sort;
Var I, J: low(Tab)..high(Tab);
Tmp : TElement;
Procedure Swap(Cond: Boolean);
Begin
if (Cond) Then
Begin
Tmp := Tab[J];
Tab[J] := Tab[J+1];
Tab[J+1] := Tmp;
End;
End;
Begin
For I := high(Tab) Downto low(Tab) Do
For J := low(Tab) To I Do
if (I <> J) Then
Swap((Length(Tab[J].Name)> Length(Tab[J+1].Name)));
End;
Begin
Tab[0].Name := 'Jan';
Tab[1].Name := 'Magda';
Tab[2].Name := 'Ania';
Tab[3].Name := 'Tomasz';
Writeln('Domyslnie:');
Display;
Writeln('Wedlug dlugosci imienia:');
Sort;
Display;
Readln;
End.