in reply to Re^2: Need help making my Merge Sort implementation stable
in thread Need help making my Merge Sort implementation stable
use Data::Dump 'pp'; # only used for output my @data = map { [ map { int rand(3) } 1 .. 5 ] } 1 .. 10; my @sorted = sort { $a->[1] <=> $b->[1] # sort by column 1 ascending || $a->[0] <=> $b->[0] # then column 0 || $b->[3] <=> $a->[3] # then column 3 descending } @data; pp @sorted;
gives
( [0, 0, 2, 2, 2], [0, 0, 0, 0, 1], [0, 0, 2, 0, 1], [1, 0, 2, 2, 0], [2, 0, 0, 2, 2], [0, 1, 0, 1, 2], [1, 1, 0, 2, 2], [1, 1, 1, 1, 2], [0, 2, 2, 0, 0], [2, 2, 2, 0, 0], )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Need help making my Merge Sort implementation stable
by taffer (Novice) on Jul 03, 2008 at 21:15 UTC |