Friday, 5 October 2018

Insertion 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],i,n,j,r,x,y,ch,X;
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(1,4);
cprintf("Arranging in Ascending Order ");
for(i=1;i<=20;i++)
{
gotoxy(30,4);
if(i%2==0)
cprintf("\\");
else
cprintf("\/");
sound(i*100);
delay(300);
}
nosound();
gotoxy(1,4);
cprintf("                              ");
for(i=0,x=1,y=4;i<=n-1;i++,x+=5)
{
textcolor(WHITE);
if(i==0)
{
   gotoxy(x,y);
   cprintf("ÕÍÍÍÍ");
   gotoxy(x,y+1);
   cprintf("³    ");
   gotoxy(x+2,y+1);
   cprintf("%.2d",a[i]);
   gotoxy(x,y+2);
   cprintf("ÔÍÍÍÍ");
}
else if(i==n-1)
{
   gotoxy(x,y);
   cprintf("ÑÍÍÍ͸");
   gotoxy(x,y+1);
   cprintf("³    ³");
   gotoxy(x+2,y+1);
   cprintf("%.2d",a[i]);
   gotoxy(x,y+2);
   cprintf("ÏÍÍÍ;");
}
else
{
   gotoxy(x,y);
   cprintf("ÑÍÍÍÍ");
   gotoxy(x,y+1);
   cprintf("³    ");
   gotoxy(x+2,y+1);
   cprintf("%.2d",a[i]);
   gotoxy(x,y+2);
   cprintf("ÏÍÍÍÍ");
}
}
for(i=0,x=3,y=4;i<=n-1;i++,x+=5)
{
for(j=0;j<=n-2-i;j++)
{
    textcolor(BLUE);
    gotoxy(x,5);
    cprintf("%.2d",a[i]);
    textcolor(RED);
    gotoxy(5*(j+1)+x,5);
    cprintf("%.2d",a[i+1+j]);
    if(a[i]>a[j+1+i])
    {
    r=a[i];
    a[i]=a[i+j+1];
    a[j+i+1]=r;
    }
    sound(300);
    delay(1000);
    nosound();
    textcolor(WHITE);
    gotoxy(x,5);
    cprintf("%.2d",a[i]);
    gotoxy(5*(j+1)+x,5);
    cprintf("%.2d",a[i+1+j]);
    delay(500);
}
}

getch();
getch();
}




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

                                OUTPUT

PLEASE CLICK HERE FOR OUTPUT VIDEO

No comments:

Post a Comment