31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sorting and Searching<br />

void L.sort(int (∗cmp)(const E& , const E& ), int dd = 1)<br />

sorts the items of L using the ordering defined<br />

by the compare function cmp : E×E −→ int, with<br />

cmp(a, b)<br />

⎧<br />

⎨ < 0, if a < b<br />

= 0, if a = b<br />

⎩<br />

> 0, if a > b<br />

More precisely, if (in 1 , . . . , in n ) and<br />

(out 1 , . . . , out n ) denote the values of L<br />

before and after the call of sort, then<br />

cmp(L[out j ], L[out j+1 ]) ≤ 0 for 1 ≤ j < n<br />

and there is a permutation π of [1..n] such that<br />

out i = in πi for 1 ≤ i ≤ n .<br />

void L.sort( ) sorts the items of L using the default ordering<br />

of type E, i.e., the linear order defined by function<br />

int compare(const E&, const E&). If E is a<br />

user-defined type, you have to provide the compare<br />

function (see Section 2.3).<br />

void L.merge sort(int (∗cmp)(const E& , const E& ))<br />

sorts the items of L using merge sort and the ordering<br />

defined by cmp. <strong>The</strong> sort is stable, i.e., if<br />

x = y and 〈x〉 is before 〈y〉 in L then 〈x〉 is before<br />

〈y〉 after the sort. L.merge sort( ) is more efficient<br />

than L.sort( ) if L contains large pre-sorted intervals.<br />

void L.merge sort( ) as above, but uses the default ordering of type E.<br />

If E is a user-defined type, you have to provide the<br />

compare function (see Section 2.3).<br />

void L.bucket sort(int i, int j, int (∗b)(const E& ))<br />

void L.bucket sort(int (∗b)(const E& ))<br />

sorts the items of L using bucket sort, where b<br />

maps every element x of L to a bucket b(x) ∈ [i..j].<br />

If b(x) < b(y) then 〈x〉 appears before 〈y〉 after the<br />

sort. If b(x) = b(y), the relative order of x and y<br />

before the sort is retained, thus the sort is stable.<br />

sorts list into increasing order as prescribed by<br />

b Precondition: b is an integer-valued function on<br />

E.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!