-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (48 loc) · 1.54 KB
/
main.cpp
File metadata and controls
58 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <array>
#include <random>
#include <iostream>
#include "raylib.h"
#include "button.hpp"
#include "selection.hpp"
#include "bubble.hpp"
#include "insertion.hpp"
int main() {
const int WINDOW_HEIGHT = 1080;
const int WINDOW_WIDTH = 1920;
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Sorting Algorithms");
ToggleFullscreen();
SetTargetFPS(144);
std::array<int, 100> mainArray;
// Create an array with values 1-100 randomly in an array
srand(time(NULL));
int temp;
bool valid = false;
for(int i = 0; i < mainArray.size(); i++) {
do {
temp = (rand()%mainArray.size())+1;
valid = true;
for(int i = 0; i < mainArray.size(); i++) {
if(temp == mainArray[i]) {
valid = false;
}
}
} while(!valid);
mainArray[i] = temp;
valid = false;
}
Button bubble(10, 10, 100, "Bubble Sort");
Button selection(10, 120, 100, "Selection Sort");
Button insertion(10, 230, 100, "Insertion Sort");
while(!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
bubble.drawButton();
selection.drawButton();
insertion.drawButton();
EndDrawing();
if(bubble.isPressed()) bubbleSort(WINDOW_WIDTH, WINDOW_HEIGHT, mainArray);
if(selection.isPressed()) selectionSort(WINDOW_WIDTH, WINDOW_HEIGHT, mainArray);
if(insertion.isPressed()) insertionSort(WINDOW_WIDTH, WINDOW_HEIGHT, mainArray);
}
CloseWindow();
}