2010-12-21 00:44:06 -08:00
|
|
|
use std;
|
|
|
|
|
|
|
|
fn check_sort(vec[int] v1, vec[int] v2) {
|
2011-05-17 20:41:41 +02:00
|
|
|
auto len = std::vec::len[int](v1);
|
2010-12-21 00:44:06 -08:00
|
|
|
fn lteq(&int a, &int b) -> bool {
|
|
|
|
ret a <= b;
|
|
|
|
}
|
|
|
|
auto f = lteq;
|
2011-05-12 17:24:54 +02:00
|
|
|
auto v3 = std::sort::merge_sort[int](f, v1);
|
2010-12-21 00:44:06 -08:00
|
|
|
auto i = 0u;
|
|
|
|
while (i < len) {
|
|
|
|
log v3.(i);
|
2011-05-02 17:47:24 -07:00
|
|
|
assert (v3.(i) == v2.(i));
|
2010-12-21 00:44:06 -08:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
{
|
2011-05-16 18:21:22 -07:00
|
|
|
auto v1 = [3,7,4,5,2,9,5,8];
|
|
|
|
auto v2 = [2,3,4,5,5,7,8,9];
|
2010-12-21 00:44:06 -08:00
|
|
|
check_sort(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-16 18:21:22 -07:00
|
|
|
auto v1 = [1,1,1];
|
|
|
|
auto v2 = [1,1,1];
|
2010-12-21 00:44:06 -08:00
|
|
|
check_sort(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-16 18:21:22 -07:00
|
|
|
let vec[int] v1 = [];
|
|
|
|
let vec[int] v2 = [];
|
2010-12-21 00:44:06 -08:00
|
|
|
check_sort(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-16 18:21:22 -07:00
|
|
|
auto v1 = [9];
|
|
|
|
auto v2 = [9];
|
2010-12-21 00:44:06 -08:00
|
|
|
check_sort(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-16 18:21:22 -07:00
|
|
|
auto v1 = [9,3,3,3,9];
|
|
|
|
auto v2 = [3,3,3,9,9];
|
2010-12-21 00:44:06 -08:00
|
|
|
check_sort(v1, v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|