continue;
if (!first)
first = child;
- if (!first_opposite && child->num != -1)
+ if (!first_opposite || (child->num != -1 && child->num < first_opposite->num))
first_opposite = child;
if (child == current) {
found_current = true;
continue;
if (!last)
last = child;
- if (!first_opposite && child->num != -1)
+ if (!first_opposite || (child->num != -1 && child->num > first_opposite->num))
first_opposite = child;
if (child == current) {
found_current = true;