libstd: Implement a Sort trait.
This depends on the previous fix to not assert.
This commit is contained in:
parent
5573ad723f
commit
8f840f9ea0
1 changed files with 9 additions and 0 deletions
|
@ -9,6 +9,7 @@ export le;
|
||||||
export merge_sort;
|
export merge_sort;
|
||||||
export quick_sort;
|
export quick_sort;
|
||||||
export quick_sort3;
|
export quick_sort3;
|
||||||
|
export Sort;
|
||||||
|
|
||||||
type le<T> = pure fn(v1: &T, v2: &T) -> bool;
|
type le<T> = pure fn(v1: &T, v2: &T) -> bool;
|
||||||
|
|
||||||
|
@ -160,6 +161,14 @@ fn quick_sort3<T: copy Ord Eq>(arr: &[mut T]) {
|
||||||
qsort3(arr, 0, (arr.len() - 1) as int);
|
qsort3(arr, 0, (arr.len() - 1) as int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait Sort {
|
||||||
|
fn qsort(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: copy Ord Eq> &[mut T] : Sort {
|
||||||
|
fn qsort(self) { quick_sort3(self); }
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_qsort3 {
|
mod test_qsort3 {
|
||||||
fn check_sort(v1: &[mut int], v2: &[mut int]) {
|
fn check_sort(v1: &[mut int], v2: &[mut int]) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue