1--
2-- Copyright (C) 1998
3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4--
5-- Permission to use, copy, modify, and distribute this
6-- software and its documentation for EDUCATIONAL purposes
7-- and without fee is hereby granted provided that this
8-- copyright notice appears in all copies.
9--
10--
11
12-- date : January 1, 1998.
13-- author : Salih Yurttas.
14
15-- purpose : sorting of a list of integers/floats
16-- in ascending/descending order
17-- using Bubble-Sort.
18
19-- bsortif_ad_10.adb
20
21
22with Text_IO; use Text_IO;
23
24with ListIF_P; use ListIF_P;
25with I_ListIF_P; use I_ListIF_P;
26with O_ListIF_P; use O_ListIF_P;
27
28with BSortEL_AD_00_P; use BSortEL_AD_00_P;
29
30procedure BSortIF_AD_10 is
31
32 N : constant Integer := 16;
33
34 Y_N : Character := 'Y';
35 I_F : Character;
36 A_D : Character;
37
38 List_Count : Integer;
39
40 PageHeaderI : String := "The sorted list of integers ";
41 PageHeaderF : String := "The sorted list of floats ";
42 PageHeaderA : String := "in descending order are : ";
43 PageHeaderD : String := "in ascending order are : ";
44
45 PageHeader : String(1..54);
46
47begin
48
49 while Y_N = 'Y' or Y_N = 'y'
50 loop
51
52 Put("--> I_F : I for Integer,"); New_Line;
53 Put(" F for Float : ");
54
55 Get(I_F); Skip_Line;
56 New_Line;
57
58 Put("--> A_D : A for Ascending,"); New_Line;
59 Put(" D for Desscending : ");
60
61 Get(A_D); Skip_Line;
62 New_Line;
63
64 case I_F is
65 when 'I' | 'i' =>
66 declare
67 D_ListI : ListI(1..N);
68 begin
69
70 GetIL(List_Count, D_ListI);
71
72 case A_D is
73 when 'A' | 'a' =>
74 declare
75 procedure Bubble_SortI_A is new Bubble_SortE(Element => Integer,
76 ListE => ListI,
77 Compare => ">");
78 begin
79 Bubble_SortI_A(List_Count, D_ListI);
80 PageHeader := PageHeaderI & PageHeaderA;
81 end;
82 when 'D' | 'd' =>
83 declare
84 procedure Bubble_SortI_D is new Bubble_SortE(Element => Integer,
85 ListE => ListI,
86 Compare => "<");
87 begin
88 Bubble_SortI_D(List_Count, D_ListI);
89 PageHeader := PageHeaderI & PageHeaderD;
90 end;
91 when others => null;
92 end case;
93
94 PutIL(List_Count, D_ListI, PageHeader);
95
96 end;
97
98 when 'F' | 'f' =>
99 declare
100 D_ListF : ListF(1..N);
101 begin
102
103 GetFL(List_Count, D_ListF);
104
105 case A_D is
106 when 'A' | 'a' =>
107 declare
108 procedure Bubble_SortF_A is new Bubble_SortE(Element => Float,
109 ListE => ListF,
110 Compare => ">");
111 begin
112 Bubble_SortF_A(List_Count, D_ListF);
113 PageHeader := PageHeaderF & PageHeaderA;
114 end;
115 when 'D' | 'd' =>
116 declare
117 procedure Bubble_SortF_D is new Bubble_SortE(Element => Float,
118 ListE => ListF,
119 Compare => "<");
120 begin
121 Bubble_SortF_D(List_Count, D_ListF);
122 PageHeader := PageHeaderF & PageHeaderD;
123 end;
124 when others => null;
125 end case;
126
127 PutFL(List_Count, D_ListF, PageHeader);
128
129 end;
130
131 when others => null;
132
133 end case;
134
135 New_Line(2);
136 Put("--> Y_N : Y for Continue,"); New_Line;
137 Put(" N for Stop : ");
138
139 Get(Y_N); Skip_Line;
140 New_Line;
141
142 end loop;
143
144end BSortIF_AD_10;