Guys this is the code in c++ of bubble sort but i don't how to show it's output in animation> what kind of project should i made in visual studio and what libraries should i use? please help me guys i really want your help.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
void PrintCurrentState(int numbers[], int max, int j)
{
int i, temp, midt;
clrscr();
printf("\nThe elements are:\n");
for(i = 0; i<max; i++)
{
if (i == j-1)
{
textcolor(GREEN);
gotoxy(wherex(), wherey()+1);
temp = cprintf("%c",24);
gotoxy(wherex()-temp, wherey()-1);
}
else if(i == j)
{
textcolor(GREEN);
gotoxy(wherex(), wherey()+1);
if (numbers[j-1] > numbers[j])
temp = cprintf("%c Will swap",24);
else
temp = cprintf("%c Will not swap",24);
gotoxy(wherex()-temp, wherey()-1);
}
cprintf("%d", numbers[i]);
printf(" ");
textcolor(LIGHTGRAY);
}
delay(1000);
}
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
_setcursortype(_NOCURSOR);
for (i = (array_size - 1); i >= 0; i--)
for (j = 1; j <= i; j++)
{
PrintCurrentState(numbers, array_size, j);
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
PrintCurrentState(numbers, array_size, array_size+1);
_setcursortype(_NORMALCURSOR);
printf("\n\nList is sorted!");
}
int main()
{
int i, a[100], max;
clrscr();
printf("Enter total number of elements:");
scanf("%d", &max);
printf("\nEnter the elements :\n\n");
for (i=0; i<max;i++)
{
printf("Enter %d element:", i+1);
scanf("%d", &a[i]);
}
bubbleSort(a, max);
getch();
}