Sorting is used in arrays to making searching for information
quicker. When you start writing programs for storing data, you will
use programs for sorting.
| with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO; procedure Sort is Max_Elements : constant := 5; subtype Index is Integer range 1 .. Max_Elements; type Integer_Array is array (Index) of Integer; A : Integer_Array; Num_Elements : Natural := 0; L : Index; Temp : integer; begin Put_Line ("Enter 5 whole numbers seperated by a space"); while Num_Elements < Max_Elements loop Num_Elements:= Num_Elements + 1; Get (A(Num_Elements)); end loop; for J in 1 .. Num_Elements loop
Temp := A(J);
New_Line;
|
When this sorting program is run, the ouput is as follows:
Enter 5 whole numbers seperated by a space
5 -9 22 0 -999
-999 -9 0 5
22
Go to the Tutorial Table of Contents