-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsaproject.cpp
More file actions
60 lines (55 loc) · 1.18 KB
/
dsaproject.cpp
File metadata and controls
60 lines (55 loc) · 1.18 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
59
60
#include <graphics.h>
#include <iostream>
#include <conio.h>
#include<dos.h>
#include<ctime>
using namespace std;
void drawArray(int arr[], int n, int highlight1 = -1, int highlight2 = -1) {
cleardevice();
int base = 400;
for (int i = 0; i < n; i++) {
int height = arr[i] * 5;
int left = 50 + i * 50;
int top = base - height;
int right = left + 30;
int bottom = base;
if (i == highlight1 || i == highlight2)
setfillstyle(SOLID_FILL, RED);
else
setfillstyle(SOLID_FILL, GREEN);
bar(left, top, right, bottom);
}
delay(1000);
}
void insertionSortVisual(int arr[], int n) {
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
drawArray(arr, n, j, j + 1);
j--;
}
arr[j + 1] = key;
drawArray(arr, n, j + 1);
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int a;
cout<<"Enter no. of array elements"<<endl;
cin>>a;
int arr[10];
for(int i=0;i<a;i++)
{
cout<<"Enter array elements"<<endl;
cin>>arr[i];
}
drawArray(arr, a);
getch();
insertionSortVisual(arr, a);
getch();
closegraph();
return 0;
}