Wednesday, 15 January 2014

C++ Program To Bubble Search

#include<iostream.h>
#include<conio.h>
void main()
{

int a[50];
clrscr();
cout<<"enter no of elements:";
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"a["<<i<<"]:";
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]:"<<a[i]<<endl;
}
for(int j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(a[i+1]<a[i])
{
   int temp=a[i+1];
   a[i+1]=a[i];
   a[i]=temp;
}
}
}
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]:"<<a[i]<<endl;
}
getch();

}

No comments:

Post a Comment