VisualSort
- 8 Devlogs
- 21 Total hours
I'm building a C++ software to visualize sorting algorithms!
I'm building a C++ software to visualize sorting algorithms!
There we are after another week.. it’s gonna be quick since I didn’t change many things.
After reworking the entire code to use vectors, I managed to add the merge sort algorithm!
I had to use some AI because after making the basic implementation, it just kept crashing the program.
The problem was that the function that merged everything had recursions in it, and since my way of visualizing this sorting algorithms is step-by-step, it would cause calling the function too many times until it crashed.
Anyway, after fixing with ChatGPT now it works well and it shouldn’t have any problem!
Next thing I’ll work on is:
Here’s a quick screenshot of the merge algorithm working!
And there we are! After about.. a week from the last devlog and I’ve made some changes since then!
Now the entire code uses vectors instead of arrays!
At first I used arrays cause it was the only thing I knew, but I read some guides about vectors and I refactored the entire code to use them instead!
After doing this, I can easily implement merge sort and quick sort!
While reworking the code, I had quite some problems with the selection sort and insertion sort since it crashed the program when I tried to sort the values.
I tried everything, but once I found the problems, I didn’t know how to fix them.
So unfortunately, I had to use ChatGPT to help me fix them since I really didn’t know how.
(Every change I made with AI it’s tagged with the prefix //AI: in the comments of the code.)
I didn’t want to use AI cause I want to learn these things by myself and without any help of AI, after all I’m still learning and I said at first that this project it’s just a way for me to practice.
But I guess it’s fine to get help from time to time, I just need to not do it often and try by myself first!
That’s all for this devlog and see you in another devlog!
(Yeah, the screenshot is the same as the previous one since I didn’t change anything graphically, lol)
Hey there, this is going to be another quick devlog..
I usually post devlogs as I make commits so, everytime I commit something to the repo I make a devlog and say what I did, lol
Anyway.. there we go.
Yayyy! I’ve finally added statistics!
So now, every time you finish sorting a range of values, it shows how many comparisons and swaps the algorithm performed and how many array accesses it made!
It wasn’t hard to implement but for now it works only for bubble sort and selection sort! (I was lazy and didn’t want to add it yesterday lol).
And still isn’t quite complete.. cause I don’t know for what reason but if I compare the statistics with a normal implementation of the algorithm, my Selection sort appears to do one cycle more than it needs too.. So I have to check that out.
After adding the statistics I just cleaned up some code, added some comments so people can actually understand what everything does and then added a quick button to show/hide the text under the rectangles with a limit. The limit is there so that you can still see the text of the rectangles without them overlapping on each other.
Hey there and there we are in another devlog! This is going to be quite short but whatever.
I added a new algorithm, the Insertion sort!
I tested it multiple times and I managed to get it to work in about an hour.
Then, I even fixed a bug where sometimes a value would disappear.. (I didn’t put a “=” , lol)
Next thing is going to be to add simple stats about the algorithm. Like I said in the previous devlog it’s going to be:
Another thing I’ll work on is to add a way to show/hide the actual value of a rectangle. It will have a limit, cause when you decide to widen the quantity of values, they don’t have enough space to see the text of the value clearly.
I won’t focus on them for now since I already implemented some starting algorithms. I first want to polish some code (It’s going to be bad anyway) and add these little features first..
The reason? Well, I wanted to add Quick sort and Merge sort but they’re quite hard to create in the style I need.. and I noticed that they might need vectors to work.. and they haven’t teached me vectors at school…
So first, I need to understand how vectors work in C++, THEN I’ll add Merge sort and Quick sort (Or I’ll just ignore them and ship the project anyway. I’ll definitely add them after shipping though)
(Oh yeah, I also need to fix how the rectangle change color when the sorting is active. It’s a bit rough now.. I need to make it better.)
Anyway see you in another devlog and thank you!
So.. It’s been a while.. (again) Unfortunately I started doing other personal things and forgot about this project but I still kept doing small fixes. In fact, I had a 12 day streak but unfortunately I lost it lol. Anyway.. yesterday I finally locked in again and finished what I needed to do!
I finally added the Selection sort algorithm! It was a bit harder compared to the bubble sort cause I had some problems while porting it in this new style. Another reason is because of all the refactoring I did of the main code that I’m just about to introduce! ## Splitting files! Like I said in the beginning, this project is a way for me to get better at coding, learn sorting algorithms and even learn new approaches into coding that I haven’t learned at school! For this reason, I decided to learn more about header files and how to split the code on multiple files instead of having just one big .cpp file! As of now, the structure look like this!
VisualSort/
├── images/
│ └── image1.png
├── src/
│ ├── algorithms/
│ │ ├── bubbleSort.h
│ │ └── selectionSort.h
│ ├── main.cpp
│ └── main.h
├── .gitignore
├── CMakeLists.txt
└── README.md
So now I have the main.h for all the variables needed for the sorting algorithms and the main GUI to function.
Then, I have a folder called algorithms where I have all the header files of the algorithms I implemented! (I know that I should make a .h and .cpp file and that the header is only for declaration but I didn’t want to add more files since it’s a simple project).
Now, I even added a slider bar to let the user choose the speed of the sorting algorithm! The slider changes the seconds of the delay between every step of the algorithm and it goes from a minimum of 0.1 sec (fastest) and a maximum of 2.0 (slowest).
After all of this I think I’m gonna add atleast 1 or 2 new algorithms, a box to show a quick description of the algorithm and then some stats about the like:
If you ask why I took 4h 36min to implement ONLY these features it’s because I’m not really quick at coding and everytime I tried to implement the Selection sort I always had problems.. and other than that I even had to refactor all the code to divide it into files unfortunately.
Anyway, that’s all and see you in the next devlog! Hoping that it will be soon. If I lock in it should be tomorrow maybe or I don’t know. Before saying goodbye, here’s a quick screenshot of how the software looks now!
It’s been a while since my last devlog. Since then, I spent all the time working on the delay between each swap of rectangles. I know that it sounds silly but I really didn’t know how to do it.. But now, I managed to solve it and now it works!
The problem was that, to start the sorting algorithm, I would press a button and it would call the sorting function. But.. once it starts, it does everything in ONE frame, instead of waiting for the delay I set.
So once I understood my mistake, I rewrote the algorithm in the exact same way but in a step-by-step style, without using any kind of loops.
Now, thanks to this new approach, I managed to add a delay between the swaps!
Thanks to this, I even managed to add a simple animation when the sorting is completed!
The next features that I’m working to add is:
Anyway thanks for reading this new devlog and see you onto the next one!
Hey there! This is the second devlog of my project. I wanted to make it yesterday but I was busy, lol.
Anyway, I started implementing a reallyyy rough (I mean really rough) draft of the GUI of the software!
Of course, since I’m using the Raylib library, for the GUI I’m using the Raygui library! It was a bit hard to understand at first because of all the types of GUI available, but thanks to the tools offered by raysan5 (aka the creator of Raylib), I managed to find what I needed!
(Raysan5 is the real goat, y’all should definitely check him out and all of his work. Especially the raylib library if you want to code a game in the most spartan and raw way possible! Trust me, it’s a real piece of art this library.)
Of course, once I’m satisfied of how the code is and after implementing all the features I had in mind, I’ll improve the GUI.
That’s mainly because I want to focus first on cleaning the code, optimize it, add the algoritms I want and every feature that I had in mind. Only by then I’ll work on the GUI again, as of now, the positions of the controls on screen are random cause I still need to test them after all!
After talking about the GUI, let’s talk about algoritms!The first one I implemented it’s the bubble sort! Quite easy to implement and it works well! Next time, I’ll try to add something else but I doubt cause I still need to do some things first, then I’ll work on adding as many algoritms as possible.
Of course, when the software starts sorting, I’d like to add some kind of delay to see the rectangles swap places… I though it was easy.. Well.. It isn’t. I spent 1h 30mins just to try and this damn delay and it still doesn’t work. It’s a pain. I hate this. But I should be close to get it right.. Or at least that’s what I hope..
And of course, I shall use no AI to help me in this task and suffer through it. I need to learn on how to overtake this difficulties, so NO Ai and just raw searching on Google, checking out other people’s codes to see if I can apply something to my case, check examples by raylib and the docs, reddit’s posts and anything else that is available, except AI.
This was pretty much everything. I already started writing some code but
it isn’t much. I just made the basics and they already need some fixing. This is a quick screenshot of the project as of now. I’ll definitely fix it up tomorrow. Anyway, thanks for
everything and see you in another Devlog!