item pointer array
Solved
General and Desktop
-
#define WAIT_A_MINUTE_2 \ while (isPause) \ { \ if (isReset) \ return; \ QTest::qWait(10); \ } \ QTest::qWait(speed); int number[15]; RectItem *rect[15]; void startSort() { isPause = false; isReset = false; RectItem *item; int temp; int j; WAIT_A_MINUTE_2 rect[0]->setItemColor(RectItem::CYAN); for (int i = 1; i < n; i++) { WAIT_A_MINUTE_2 rect[i]->setItemColor(RectItem::RED); rect[i]->setPos(QPoint(0, dropDistance)); item = rect[i]; temp = number[i]; j = i - 1; while (j >= 0 && number[j] > temp) { WAIT_A_MINUTE_2 item->setPos(QPoint(-75, 0)); rect[j]->setPos(QPoint(75, 0)); number[j + 1] = number[j]; rect[j + 1] = rect[j]; j--; } WAIT_A_MINUTE_2 item->setPos(QPoint(0, -dropDistance)); item->setItemColor(RectItem::CYAN); number[j + 1] = temp; rect[j + 1] = item; } emit finished(); }
the ideal result of the code is:https://visualgo.net/en/sorting (choose [insert_sort])。
but the actual result is:
I checked many times, but i didn't find any error. Look the error in the above picture, I guessed that there may be some problem in item pointer array, but I checked it carefully, no errors.