Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. item pointer array
Forum Updated to NodeBB v4.3 + New Features

item pointer array

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 445 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by
    #1
    #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:

    0_1515572277115_12000000.gif

    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.

    1 Reply Last reply
    0
    • LimerL Offline
      LimerL Offline
      Limer
      wrote on last edited by
      #2

      solved, setPos will not change the item's positon.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved