Reversing all elements in an array |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
List : System.Collections.ArrayList;
i : Integer;
begin
// Create our array list object
List := ArrayList.Create;
// Fill it
List.Add('0.');
List.Add('1.-');
List.Add('2.--');
List.Add('3.---');
// Display List contents : note the 0 indexing
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
// Reverse the order of the array
Console.WriteLine;
Console.WriteLine('Reversing the list order :');
Console.WriteLine;
List.Reverse;
// Display List contents again
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
Console.Readline;
end.
|
Show full unit code |
0.
1.-
2.--
3.---
Reversing the list order :
3.---
2.--
1.-
0.
|
|
Reversing just a subset of array elements |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
List : System.Collections.ArrayList;
i : Integer;
begin
// Create our array list object
List := ArrayList.Create;
// Fill it
List.Add('0.');
List.Add('1.-');
List.Add('2.--');
List.Add('3.---');
// Display List contents : note the 0 indexing
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
// Reverse the middle 2 elements of the array
Console.WriteLine;
Console.WriteLine('Reversing the middle 2 elements :');
Console.WriteLine;
List.Reverse(1, 2);
// Display List contents again
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
Console.Readline;
end.
|
Show full unit code |
0.
1.-
2.--
3.---
Reversing the middle 2 elements :
0.
2.--
1.-
3.---
|
|
|