mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
fix nth_element
This commit is contained in:
parent
098dd1721e
commit
13e0c9b5f5
1 changed files with 9 additions and 0 deletions
|
@ -132,24 +132,33 @@ namespace sprout {
|
|||
return;
|
||||
}
|
||||
do {
|
||||
bool not_sorted_flag = false;
|
||||
if (n_swaps == 0) {
|
||||
if (nth < i) {
|
||||
j = m = first;
|
||||
while (++j != i) {
|
||||
if (comp(*j, *m)) {
|
||||
not_sorted_flag = true;
|
||||
break;
|
||||
}
|
||||
m = j;
|
||||
}
|
||||
if (not_sorted_flag) {
|
||||
break;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
j = m = i;
|
||||
while (++j != last) {
|
||||
if (comp(*j, *m)) {
|
||||
not_sorted_flag = true;
|
||||
break;
|
||||
}
|
||||
m = j;
|
||||
}
|
||||
if (not_sorted_flag) {
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue