Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,41 +0,0 @@
|
|||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
with Ada.Containers.Generic_Array_Sort;
|
||||
|
||||
procedure Demo_Array_Sort is
|
||||
|
||||
function "+" (S : String) return Unbounded_String renames To_Unbounded_String;
|
||||
|
||||
type A_Composite is
|
||||
record
|
||||
Name : Unbounded_String;
|
||||
Value : Unbounded_String;
|
||||
end record;
|
||||
|
||||
function "<" (L, R : A_Composite) return Boolean is
|
||||
begin
|
||||
return L.Name < R.Name;
|
||||
end "<";
|
||||
|
||||
procedure Put_Line (C : A_Composite) is
|
||||
begin
|
||||
Put_Line (To_String (C.Name) & " " & To_String (C.Value));
|
||||
end Put_Line;
|
||||
|
||||
type An_Array is array (Natural range <>) of A_Composite;
|
||||
|
||||
procedure Sort is new Ada.Containers.Generic_Array_Sort (Natural, A_Composite, An_Array);
|
||||
|
||||
Data : An_Array := (1 => (Name => +"Joe", Value => +"5531"),
|
||||
2 => (Name => +"Adam", Value => +"2341"),
|
||||
3 => (Name => +"Bernie", Value => +"122"),
|
||||
4 => (Name => +"Walter", Value => +"1234"),
|
||||
5 => (Name => +"David", Value => +"19"));
|
||||
|
||||
begin
|
||||
Sort (Data);
|
||||
for I in Data'Range loop
|
||||
Put_Line (Data (I));
|
||||
end loop;
|
||||
end Demo_Array_Sort;
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
with Ada.Containers.Ordered_Sets;
|
||||
|
||||
procedure Sort_Composites is
|
||||
|
||||
function "+" (S : String) return Unbounded_String renames To_Unbounded_String;
|
||||
|
||||
type A_Composite is
|
||||
record
|
||||
Name : Unbounded_String;
|
||||
Value : Unbounded_String;
|
||||
end record;
|
||||
|
||||
function "<" (L, R : A_Composite) return Boolean is
|
||||
begin
|
||||
return L.Name < R.Name;
|
||||
end "<";
|
||||
|
||||
procedure Put_Line (C : A_Composite) is
|
||||
begin
|
||||
Put_Line (To_String (C.Name) & " " & To_String (C.Value));
|
||||
end Put_Line;
|
||||
|
||||
package Composite_Sets is new Ada.Containers.Ordered_Sets (A_Composite);
|
||||
|
||||
procedure Put_Line (C : Composite_Sets.Cursor) is
|
||||
begin
|
||||
Put_Line (Composite_Sets.Element (C));
|
||||
end Put_Line;
|
||||
|
||||
Data : Composite_Sets.Set;
|
||||
|
||||
begin
|
||||
Data.Insert (New_Item => (Name => +"Joe", Value => +"5531"));
|
||||
Data.Insert (New_Item => (Name => +"Adam", Value => +"2341"));
|
||||
Data.Insert (New_Item => (Name => +"Bernie", Value => +"122"));
|
||||
Data.Insert (New_Item => (Name => +"Walter", Value => +"1234"));
|
||||
Data.Insert (New_Item => (Name => +"David", Value => +"19"));
|
||||
Data.Iterate (Put_Line'Access);
|
||||
end Sort_Composites;
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
with Ada.Text_Io;
|
||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
|
||||
procedure Sort_Composite is
|
||||
type Composite_Record is record
|
||||
Name : Unbounded_String;
|
||||
Value : Unbounded_String;
|
||||
end record;
|
||||
|
||||
type Pairs_Array is array(Positive range <>) of Composite_Record;
|
||||
|
||||
procedure Swap(Left, Right : in out Composite_Record) is
|
||||
Temp : Composite_Record := Left;
|
||||
begin
|
||||
Left := Right;
|
||||
Right := Temp;
|
||||
end Swap;
|
||||
|
||||
-- Sort_Names uses a bubble sort
|
||||
|
||||
procedure Sort_Name(Pairs : in out Pairs_Array) is
|
||||
Swap_Performed : Boolean := True;
|
||||
begin
|
||||
while Swap_Performed loop
|
||||
Swap_Performed := False;
|
||||
for I in Pairs'First..(Pairs'Last - 1) loop
|
||||
if Pairs(I).Name > Pairs(I + 1).Name then
|
||||
Swap (Pairs(I), Pairs(I + 1));
|
||||
Swap_Performed := True;
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
end Sort_Name;
|
||||
|
||||
procedure Print(Item : Pairs_Array) is
|
||||
begin
|
||||
for I in Item'range loop
|
||||
Ada.Text_Io.Put_Line(To_String(Item(I).Name) & ", " &
|
||||
to_String(Item(I).Value));
|
||||
end loop;
|
||||
end Print;
|
||||
type Names is (Fred, Barney, Wilma, Betty, Pebbles);
|
||||
type Values is (Home, Work, Cook, Eat, Bowl);
|
||||
My_Pairs : Pairs_Array(1..5);
|
||||
begin
|
||||
for I in My_Pairs'range loop
|
||||
My_Pairs(I).Name := To_Unbounded_String(Names'Image(Names'Val(Integer(I - 1))));
|
||||
My_Pairs(I).Value := To_Unbounded_String(Values'Image(Values'Val(Integer(I - 1))));
|
||||
end loop;
|
||||
Print(My_Pairs);
|
||||
Ada.Text_Io.Put_Line("=========================");
|
||||
Sort_Name(My_Pairs);
|
||||
Print(My_Pairs);
|
||||
end Sort_Composite;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var elements := new object[]{
|
||||
auto elements := new object[]{
|
||||
KeyValue.new("Krypton", 83.798r),
|
||||
KeyValue.new("Beryllium", 9.012182r),
|
||||
KeyValue.new("Silicon", 28.0855r),
|
||||
|
|
@ -15,6 +15,6 @@ public program()
|
|||
|
||||
sorted.forEach::(element)
|
||||
{
|
||||
console.printLine(element.Key," - ",element)
|
||||
Console.printLine(element.Key," - ",element)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
include sort.e
|
||||
include misc.e
|
||||
|
||||
constant NAME = 1
|
||||
function compare_names(sequence a, sequence b)
|
||||
return compare(a[NAME],b[NAME])
|
||||
end function
|
||||
|
||||
sequence s
|
||||
s = { { "grass", "green" },
|
||||
{ "snow", "white" },
|
||||
{ "sky", "blue" },
|
||||
{ "cherry", "red" } }
|
||||
|
||||
pretty_print(1,custom_sort(routine_id("compare_names"),s),{2})
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
$list = @{
|
||||
"def" = "one"
|
||||
"abc" = "two"
|
||||
"jkl" = "three"
|
||||
"abcdef" = "four"
|
||||
"ghi" = "five"
|
||||
"ghijkl" = "six"
|
||||
}
|
||||
$list.GetEnumerator() | sort {-($PSItem.Name).length}, Name
|
||||
|
|
@ -1,47 +1,32 @@
|
|||
include Settings
|
||||
-- 19 Jan 2026
|
||||
include Setting
|
||||
|
||||
say 'SORT COMPOSITE ARRAY - 5 Mar 2025'
|
||||
say 'SORT COMPOSITE ARRAY'
|
||||
say version
|
||||
say
|
||||
call Create
|
||||
call Show 'Not ordered'
|
||||
call SortStateCity
|
||||
call Show 'By state and city'
|
||||
call SortPopCityN
|
||||
call Show 'By pop (numeric desc) and city'
|
||||
table = 'states.'; keys = 'pop. state.'; data = 'city.'
|
||||
call SortPopCityS table,keys,data
|
||||
call Show 'By pop (string) and city'
|
||||
table = 'states.'; keys = 'city. state.'; data = 'pop.'
|
||||
call SortCityState table,keys,data
|
||||
call Show 'By city and state'
|
||||
return
|
||||
|
||||
Create:
|
||||
states = 'States.txt'
|
||||
call Stream states,'c','open read'
|
||||
states. = ''; n = 0
|
||||
do while lines(states) > 0
|
||||
record = linein(states)
|
||||
parse var record rstate','rcity','rpop
|
||||
n = n+1; states.state.n = rstate; states.city.n = rcity; states.pop.n = rpop
|
||||
end
|
||||
call Stream states,'c','close'
|
||||
states.0 = n
|
||||
return
|
||||
call Stemread 'States.txt','states.state. states.city. states.pop.'
|
||||
call Show 'Not ordered','A'
|
||||
call Stemsort 'states.state. states.city.','states.pop.'
|
||||
call Show 'By state and city','A'
|
||||
call Stemsort 'states.pop.','states.state. states.city.'
|
||||
call Show 'By pop (desc)','D'
|
||||
exit
|
||||
|
||||
Show:
|
||||
procedure expose states.
|
||||
arg header
|
||||
say center(header,53)
|
||||
say right('row',3) left('state',20) left('city',20) right('pop',7)
|
||||
do n = 1 to states.0
|
||||
say right(n,3) left(states.state.n,20) left(states.city.n,20) right(states.pop.n,7)
|
||||
arg header,seq
|
||||
say Center(header,53)
|
||||
say Right('row',3) Left('state',20) Left('city',20) Right('pop',7)
|
||||
if seq='A' then do
|
||||
a=1; i=1; z=states.0
|
||||
end
|
||||
else do
|
||||
a=states.0; i=-1; z=1
|
||||
end
|
||||
do n=a by i to z
|
||||
say Right(n,3) Left(states.state.n,20) Left(states.city.n,20) Right(states.pop.n,7)
|
||||
end
|
||||
say
|
||||
return
|
||||
|
||||
include Quicksort21 [label]=SortStateCity [table]=states. [key1]=state. [key2]=city. [data1]=pop.
|
||||
include Quicksort21 [label]=SortPopCityN [table]=states. [key1]=pop. [key2]=city. [data1]=state. [lt]=> [gt]=<
|
||||
include Quicksort [label]=SortCityState
|
||||
include Quicksort [label]=SortPopCityS [lt]=<< [gt]=>>
|
||||
include Math
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue