===========================================================================
CODING
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
clrscr();
int a[80],i,n,j,r,b[80],search,mid,beg,end,x,y,X,k,co,no,small,large;
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(40,1);
cprintf("What do you want to search: ");
cscanf("%d",&search);
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-2;i++,x+=5)
{
textcolor(5);
gotoxy(20,10);
cprintf("Iteration->%d",i+1);
textcolor(BLUE);
gotoxy(x,5);
cprintf("%.2d",a[i]);
gotoxy(x,7);
cprintf(" ");
gotoxy(x,8);
cprintf("³");
gotoxy(x-1,9);
cprintf("KEY");
textcolor(YELLOW);
for(k=0;k<=0;k++)
{
for(j=k+1;j<=n-2-i;j++)
{
textcolor(YELLOW);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
gotoxy(5*(j+1)+x,5);
cprintf("%.2d",a[i+1+j]);
gotoxy(37,10);
textcolor(3);
cprintf("PassÄ %d",j);
delay(1500);
textcolor(WHITE);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
gotoxy(5*(j+1)+x,5);
cprintf("%.2d",a[i+1+j]);
}
}
gotoxy(37,10);
cprintf(" ");
for(k=0,small=a[i+1+k],no=i+k+1,co=5*(k+1)+x;k<=n-2-i;k++)
{
textcolor(YELLOW);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
if(small>a[i+1+k])
{
small=a[i+1+k];
no=i+1+k;
co=5*(k+1)+x;
}
}
textcolor(12);
gotoxy(co,5);
cprintf("%.2d",small);
if(a[i]>small)
{
r=a[i];
a[i]=a[no];
a[no]=r;
}
sound(300);
delay(2000);
nosound();
textcolor(WHITE);
gotoxy(x,5);
cprintf("%.2d",a[i]);
for(k=0;k<=n-2-i;k++)
{
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
}
gotoxy(x,7);
cprintf(" ");
gotoxy(x,8);
cprintf(" ");
gotoxy(x-1,9);
cprintf(" ");
gotoxy(20,10);
cprintf(" ");
delay(500);
}
getch();
getch();
gotoxy(1,3);
cprintf("Processing in Binary Search ");
for(i=1;i<=20;i++)
{
gotoxy(29,3);
if(i%2==0)
cprintf("\\");
else
cprintf("\/");
sound(i*100);
delay(300);
}
nosound();
gotoxy(1,3);
cprintf(" ");
for(j=0,x=3;j<=n-1;j++,x+=5)
b[j]=x;
for(i=0,k=0,no=1,beg=i,end=n-1;beg<=end;i++)
{
if((end+beg)%2==0)
mid=(end+beg)/2;
else
mid=(end+beg+1)/2;
for(j=beg;j<=end;j++)
{
gotoxy(b[j],5);
if(j==mid)
textcolor(RED+BLINK);
else
textcolor(YELLOW);
cprintf("%.2d",a[j]);
if(j==mid)
{
gotoxy(b[j],7);
cprintf(" ");
cprintf("\n\b³");
cprintf("\n\b\bMID");
X=j;
}
}
sound(600);
delay(2000);
nosound();
if(a[mid]>search)
{
gotoxy(1,10);
textcolor(GREEN);
cprintf("As %d<Middle \r\nTerefore, Searching in ",search);
textcolor(RED+BLINK);
cprintf("Left Part....");
delay(4000);
gotoxy(1,10);
cprintf(" \r\n ");
}
else if(a[mid]<search)
{
gotoxy(1,10);
textcolor(GREEN);
cprintf("As %d>Middle \r\nTerefore, Searching in ",search);
textcolor(RED+BLINK);
cprintf("Right Part....");
delay(4000);
gotoxy(1,10);
cprintf(" \r\n ");
}
for(j=beg;j<=end;j++)
{
gotoxy(b[j],5);
textcolor(WHITE);
cprintf("%.2d",a[j]);
if(j==mid)
{
gotoxy(b[j],7);
cprintf(" ");
cprintf("\n\b ");
cprintf("\n\b\b ");
}
}
if(a[mid]==search)
{
no=0;
break;
}
if(a[mid]>search)
end=mid-1;
else if(a[mid]<search)
beg=mid+1;
}
if(no==0)
{
textcolor(RED+BLINK);
gotoxy(b[X],7);
cprintf(" ");
cprintf("\n\b³");
cprintf("\n\b\b\bSEARCH");
}
else
{
gotoxy(1,11);
textcolor(5+128);
cprintf("The integer was no where to be found");
}
getch();
}
CODING
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
clrscr();
int a[80],i,n,j,r,b[80],search,mid,beg,end,x,y,X,k,co,no,small,large;
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(40,1);
cprintf("What do you want to search: ");
cscanf("%d",&search);
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-2;i++,x+=5)
{
textcolor(5);
gotoxy(20,10);
cprintf("Iteration->%d",i+1);
textcolor(BLUE);
gotoxy(x,5);
cprintf("%.2d",a[i]);
gotoxy(x,7);
cprintf(" ");
gotoxy(x,8);
cprintf("³");
gotoxy(x-1,9);
cprintf("KEY");
textcolor(YELLOW);
for(k=0;k<=0;k++)
{
for(j=k+1;j<=n-2-i;j++)
{
textcolor(YELLOW);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
gotoxy(5*(j+1)+x,5);
cprintf("%.2d",a[i+1+j]);
gotoxy(37,10);
textcolor(3);
cprintf("PassÄ %d",j);
delay(1500);
textcolor(WHITE);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
gotoxy(5*(j+1)+x,5);
cprintf("%.2d",a[i+1+j]);
}
}
gotoxy(37,10);
cprintf(" ");
for(k=0,small=a[i+1+k],no=i+k+1,co=5*(k+1)+x;k<=n-2-i;k++)
{
textcolor(YELLOW);
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
if(small>a[i+1+k])
{
small=a[i+1+k];
no=i+1+k;
co=5*(k+1)+x;
}
}
textcolor(12);
gotoxy(co,5);
cprintf("%.2d",small);
if(a[i]>small)
{
r=a[i];
a[i]=a[no];
a[no]=r;
}
sound(300);
delay(2000);
nosound();
textcolor(WHITE);
gotoxy(x,5);
cprintf("%.2d",a[i]);
for(k=0;k<=n-2-i;k++)
{
gotoxy(5*(k+1)+x,5);
cprintf("%.2d",a[i+1+k]);
}
gotoxy(x,7);
cprintf(" ");
gotoxy(x,8);
cprintf(" ");
gotoxy(x-1,9);
cprintf(" ");
gotoxy(20,10);
cprintf(" ");
delay(500);
}
getch();
getch();
gotoxy(1,3);
cprintf("Processing in Binary Search ");
for(i=1;i<=20;i++)
{
gotoxy(29,3);
if(i%2==0)
cprintf("\\");
else
cprintf("\/");
sound(i*100);
delay(300);
}
nosound();
gotoxy(1,3);
cprintf(" ");
for(j=0,x=3;j<=n-1;j++,x+=5)
b[j]=x;
for(i=0,k=0,no=1,beg=i,end=n-1;beg<=end;i++)
{
if((end+beg)%2==0)
mid=(end+beg)/2;
else
mid=(end+beg+1)/2;
for(j=beg;j<=end;j++)
{
gotoxy(b[j],5);
if(j==mid)
textcolor(RED+BLINK);
else
textcolor(YELLOW);
cprintf("%.2d",a[j]);
if(j==mid)
{
gotoxy(b[j],7);
cprintf(" ");
cprintf("\n\b³");
cprintf("\n\b\bMID");
X=j;
}
}
sound(600);
delay(2000);
nosound();
if(a[mid]>search)
{
gotoxy(1,10);
textcolor(GREEN);
cprintf("As %d<Middle \r\nTerefore, Searching in ",search);
textcolor(RED+BLINK);
cprintf("Left Part....");
delay(4000);
gotoxy(1,10);
cprintf(" \r\n ");
}
else if(a[mid]<search)
{
gotoxy(1,10);
textcolor(GREEN);
cprintf("As %d>Middle \r\nTerefore, Searching in ",search);
textcolor(RED+BLINK);
cprintf("Right Part....");
delay(4000);
gotoxy(1,10);
cprintf(" \r\n ");
}
for(j=beg;j<=end;j++)
{
gotoxy(b[j],5);
textcolor(WHITE);
cprintf("%.2d",a[j]);
if(j==mid)
{
gotoxy(b[j],7);
cprintf(" ");
cprintf("\n\b ");
cprintf("\n\b\b ");
}
}
if(a[mid]==search)
{
no=0;
break;
}
if(a[mid]>search)
end=mid-1;
else if(a[mid]<search)
beg=mid+1;
}
if(no==0)
{
textcolor(RED+BLINK);
gotoxy(b[X],7);
cprintf(" ");
cprintf("\n\b³");
cprintf("\n\b\b\bSEARCH");
}
else
{
gotoxy(1,11);
textcolor(5+128);
cprintf("The integer was no where to be found");
}
getch();
}
===========================================================================
No comments:
Post a Comment