0

I am trying to make one of the sorting algorithm visualisations with rectangles in raylib. In my while (!WindowShouldClose()) loop, I am not sure how to thread the sorting algorithm. Here is how it looks:

    std::vector<int> rand_arr;
    for (int i = 0; i < 40; ++i) rand_arr.push_back(i);
    std::random_shuffle(rand_arr.begin(), rand_arr.end());

    while (!WindowShouldClose())
    {
        BeginDrawing();
        ClearBackground(BLACK);
        for (unsigned i = 0; i < 40; i++)
            DrawRectangle(i * 20, 800 - 20 * rand_arr[i], 20 - 1, rand_arr[i] * 20, RAYWHITE);
        EndDrawing();
    }

where rand_arr is the array storing values for rectangles and has to be sorted with std::qsort. This code currently outputs a window with rectangles aligned at random.

  • Since you have neither included any attempt at sorting the array, nor any attempt at multithreading it, I'm not sure what you are asking about – UnholySheep Oct 08 '22 at 19:39
  • Please do not use `std::qsort` but `std::sort`. The former is coming from C and should not be used from a safe C++ code (as it deals with unsafe `void*` types). – Jérôme Richard Oct 08 '22 at 19:57
  • @UnholySheep, my idea is to implement the sorting algorithm within the while loop. As the rectangles are rendering, the `rand_arr` should be simultaneously be sorted inside the while loop. – Anirudh Yamunan Govindarajan Oct 16 '22 at 06:02

0 Answers0