mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
Simplify our insertion sort implementation
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
28bf56e725
commit
04ff9c2548
1 changed files with 10 additions and 15 deletions
25
src/types.h
25
src/types.h
|
@ -485,23 +485,18 @@ inline const std::string square_to_string(Square s) {
|
||||||
/// Our insertion sort implementation, works with pointers and iterators and is
|
/// Our insertion sort implementation, works with pointers and iterators and is
|
||||||
/// guaranteed to be stable, as is needed.
|
/// guaranteed to be stable, as is needed.
|
||||||
template<typename T, typename K>
|
template<typename T, typename K>
|
||||||
void sort(K firstMove, K lastMove)
|
void sort(K first, K last)
|
||||||
{
|
{
|
||||||
T value;
|
T tmp;
|
||||||
K cur, p, d;
|
K p, q;
|
||||||
|
|
||||||
if (firstMove != lastMove)
|
for (p = first + 1; p < last; p++)
|
||||||
for (cur = firstMove + 1; cur != lastMove; cur++)
|
{
|
||||||
{
|
tmp = *p;
|
||||||
p = d = cur;
|
for (q = p; q != first && *(q-1) < tmp; --q)
|
||||||
value = *p--;
|
*q = *(q-1);
|
||||||
if (*p < value)
|
*q = tmp;
|
||||||
{
|
}
|
||||||
do *d = *p;
|
|
||||||
while (--d != firstMove && *--p < value);
|
|
||||||
*d = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|
Loading…
Add table
Reference in a new issue