Skip to content

quick_sort returns incorrect results #705

Closed

Description

std::sort::quick_sort sorts [2, 1, 3] as [1, 3, 2], for both the vec and ivec versions.

fn test_qsort() {
    auto names = ~[mutable 2, 1, 3];

    auto expected = ~[1, 2, 3];

    fn lteq(&int a, &int b) -> bool { int::le(a, b) }
    iqsort(lteq, names);

    auto pairs = ivec::zip(expected, ivec::from_mut(names));
    for (tup(int, int) p in pairs) {
        log_err #fmt("%d %d", p._0, p._1);
        assert p._0 == p._1;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions