September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
5
Task/Sort-stability/Jq/sort-stability.jq
Normal file
5
Task/Sort-stability/Jq/sort-stability.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[["UK", "London"],
|
||||
["US", "New York"],
|
||||
["US", "Birmingham"],
|
||||
["UK", "Birmingham"]]
|
||||
| sort_by(.[1])
|
||||
43
Task/Sort-stability/OoRexx/sort-stability.rexx
Normal file
43
Task/Sort-stability/OoRexx/sort-stability.rexx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* Rexx */
|
||||
Do
|
||||
cities = .array~of('UK London', 'US New York', 'US Birmingham', 'UK Birmingham',)
|
||||
|
||||
Say; Say 'Original table'
|
||||
Call display cities
|
||||
|
||||
Say; Say 'Unstable sort on city'
|
||||
sorted = cities~copy
|
||||
sorted~sortWith(.ColumnComparator~new(4, 20))
|
||||
Call display sorted
|
||||
|
||||
Say; Say 'Stable sort on city'
|
||||
sorted = cities~copy
|
||||
sorted~stableSortWith(.ColumnComparator~new(4, 20))
|
||||
Call display sorted
|
||||
|
||||
Say; Say 'Unstable sort on country'
|
||||
sorted = cities~copy
|
||||
sorted~sortWith(.ColumnComparator~new(1, 2))
|
||||
Call display sorted
|
||||
|
||||
Say; Say 'Stable sort on country'
|
||||
sorted = cities~copy
|
||||
sorted~stableSortWith(.ColumnComparator~new(1, 2))
|
||||
Call display sorted
|
||||
|
||||
Return
|
||||
End
|
||||
Exit
|
||||
|
||||
display: Procedure
|
||||
Do
|
||||
Use arg CT
|
||||
|
||||
Say '-'~copies(80)
|
||||
Loop c_ over CT
|
||||
Say c_
|
||||
End c_
|
||||
|
||||
Return
|
||||
End
|
||||
Exit
|
||||
25
Task/Sort-stability/Phix/sort-stability.phix
Normal file
25
Task/Sort-stability/Phix/sort-stability.phix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
sequence test = {{"UK","London"},
|
||||
{"US","New York"},
|
||||
{"US","Birmingham"},
|
||||
{"UK","Birmingham"}}
|
||||
|
||||
---------------------
|
||||
-- probably stable --
|
||||
---------------------
|
||||
function cmp(object a, object b)
|
||||
return compare(a[1],b[1])
|
||||
end function
|
||||
test = custom_sort(routine_id("cmp"),test)
|
||||
pp(test,{pp_Nest,1})
|
||||
|
||||
-----------------------
|
||||
-- guaranteed stable --
|
||||
-----------------------
|
||||
function tag_cmp(integer i, integer j)
|
||||
return compare({test[i][1],i},{test[j][1],j})
|
||||
-- return compare(test[i][1],test[j][1])
|
||||
end function
|
||||
sequence tags = custom_sort(routine_id("tag_cmp"),shuffle(tagset(4)))
|
||||
for i=1 to length(tags) do
|
||||
?test[tags[i]]
|
||||
end for
|
||||
28
Task/Sort-stability/Rust/sort-stability.rust
Normal file
28
Task/Sort-stability/Rust/sort-stability.rust
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
fn main() {
|
||||
let country_city = vec![("UK", "London"),
|
||||
("US", "New York"),
|
||||
("US", "Birmingham"),
|
||||
("UK", "Birmingham")];
|
||||
|
||||
let mut city_sorted = country_city.clone();
|
||||
city_sorted.sort_by_key(|k| k.1);
|
||||
|
||||
let mut country_sorted = country_city.clone();
|
||||
country_sorted.sort_by_key(|k| k.0);
|
||||
|
||||
|
||||
println!("Original:");
|
||||
for x in &country_city {
|
||||
println!("{} {}", x.0, x.1);
|
||||
}
|
||||
|
||||
println!("\nWhen sorted by city:");
|
||||
for x in &city_sorted {
|
||||
println!("{} {}", x.0, x.1);
|
||||
}
|
||||
|
||||
println!("\nWhen sorted by county:");
|
||||
for x in &country_sorted {
|
||||
println!("{} {}", x.0, x.1);
|
||||
}
|
||||
}
|
||||
2
Task/Sort-stability/Zkl/sort-stability-1.zkl
Normal file
2
Task/Sort-stability/Zkl/sort-stability-1.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fcn sortByColumn(list,col)
|
||||
{ list.sort('wrap(city1,city2){ city1[col]<city2[col] }) }
|
||||
5
Task/Sort-stability/Zkl/sort-stability-2.zkl
Normal file
5
Task/Sort-stability/Zkl/sort-stability-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
cities:=List(
|
||||
T("UK", "London"), T("US", "New York"),
|
||||
T("US", "Birmingham"),T("UK", "Birmingham"), );
|
||||
sortByColumn(cities,0).concat("\n").println("\n------");
|
||||
sortByColumn(cities,1).concat("\n").println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue