fix nth_element

This commit is contained in:
bolero-MURAKAMI 2014-04-06 18:59:20 +09:00
parent 098dd1721e
commit 13e0c9b5f5

View file

@ -132,24 +132,33 @@ namespace sprout {
return; return;
} }
do { do {
bool not_sorted_flag = false;
if (n_swaps == 0) { if (n_swaps == 0) {
if (nth < i) { if (nth < i) {
j = m = first; j = m = first;
while (++j != i) { while (++j != i) {
if (comp(*j, *m)) { if (comp(*j, *m)) {
not_sorted_flag = true;
break; break;
} }
m = j; m = j;
} }
if (not_sorted_flag) {
break;
}
return; return;
} else { } else {
j = m = i; j = m = i;
while (++j != last) { while (++j != last) {
if (comp(*j, *m)) { if (comp(*j, *m)) {
not_sorted_flag = true;
break; break;
} }
m = j; m = j;
} }
if (not_sorted_flag) {
break;
}
return; return;
} }
} }