Tuesday, 2 October 2018

Bubble Sort

===========================================================================
                                CODING



#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
#include<process.h>
#include<dos.h>

void main()
{
clrscr();
int a[80],j,i,n,r,x,y,ch;
textcolor(WHITE);
gotoxy(1,1);
cprintf("Enter no. of Observations: ");
cscanf("%d",&n);
cprintf("\r\nEnter nos.: ");
for(i=0,x=16;i<=n-1;i++,x+=5)
{
     gotoxy(x,2);
     cscanf("%d",&a[i]);
}
gotoxy(10,4);
cprintf("MENU");
gotoxy(10,5);
cprintf("ÄÄÄÄ");
gotoxy(1,6);
cprintf("1-> Ascending Order");
gotoxy(1,7);
cprintf("2-> Descending Order");
gotoxy(8,8);
cprintf("Input: ");
cscanf("%d",&ch);
gotoxy(1,10);
switch(ch)
{
case 1:
cprintf("Arranging in Ascending Order ");break;
case 2:
cprintf("Arranging in Decending Order ");break;
default:exit(0);
}
/* for(i=1;i<=20;i++)
{
gotoxy(30,10);
if(i%2==0)
cprintf("\\");
else
cprintf("\/");
sound(i*100);
delay(300);
}
nosound();
gotoxy(1,10);
cprintf("                              ");    */
for(i=0,x=1,y=11;i<=n-1;i++,x+=5)
{
textcolor(WHITE);
if(i==0)
{
   gotoxy(x,y);
   cprintf("ÕÍÍÍÍ");
   gotoxy(x,y+1);
   cprintf("³    ");
   gotoxy(x,y+2);
   cprintf("ÔÍÍÍÍ");
}
else if(i==n-1)
{
   gotoxy(x,y);
   cprintf("ÑÍÍÍ͸");
   gotoxy(x,y+1);
   cprintf("³    ³");
   gotoxy(x,y+2);
   cprintf("ÏÍÍÍ;");
}
else
{
   gotoxy(x,y);
   cprintf("ÑÍÍÍÍ");
   gotoxy(x,y+1);
   cprintf("³    ");
   gotoxy(x,y+2);
   cprintf("ÏÍÍÍÍ");
}
}
switch(ch)
{
case 1:
for(j=0,x=3;j<=n-1;j++)
{
for(i=0,y=11;i<=n-2-j;i++)
{

textcolor(5);
gotoxy(x+5*(i),12);
cprintf("%.2d",a[i]);
textcolor(YELLOW);
gotoxy(x+5*(i+1),12);
cprintf("%.2d",a[i+1]);

if(a[i]>a[i+1])
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
sound(300);
delay(1500);
nosound();
textcolor(WHITE);
gotoxy(x+5*(i),12);
cprintf("%.2d",a[i]);
gotoxy(5*(i+1)+x,12);
cprintf("%.2d",a[i+1]);
}
}
break;
case 2:
for(j=0,x=3;j<=n-1;j++)
{
for(i=0,y=11;i<=n-2-j;i++)
{
textcolor(5);
gotoxy(x+5*(i),12);
cprintf("%.2d",a[i]);
textcolor(YELLOW);
gotoxy(x+5*(i+1),12);
cprintf("%.2d",a[i+1]);

if(a[i]<a[i+1])
{
r=a[i];
a[i]=a[i+1];
a[i+1]=r;
}
sound(300);
delay(1500);
nosound();
textcolor(WHITE);
gotoxy(x+5*(i),12);
cprintf("%.2d",a[i]);
gotoxy(5*(i+1)+x,12);
cprintf("%.2d",a[i+1]);
}
}
break;
}

getch();
getch();
}




===========================================================================

                                OUTPUT


PLEASE CLICK HERE FOR OUTPUT VIDEO

No comments:

Post a Comment