Dyanmic Array (Sort, Reverse methods)



Sorting a Dyanmic Array.
Pas2JS pascal source code
var a: array of Integer; function Cmp1(const a, b: Integer): Integer; begin Result := a - b; end; function Cmp2(const a, b: Integer): Integer; begin Result := b - a; end; procedure printData; var i: Integer; begin for i := 0 to a.High do Writeln(a[i]); end; begin a.Add(3,2,1,6,18,4); //a.Sort(Cmp1); // we don't need to use a comparer function a.Reverse; printData; // 4,18,6,1,2,3 a.Reverse; printData; //3,2,1,6,18,4 a.Sort(); printData; // 1,2,3,4,6,18 //a.Sort(Cmp2); // we don't need to use a comparer function a.Reverse; printData; // 18,6,4,3,2,1