DFS :: BUBBLE

#include<iostream.h>
#include<conio.h>

/*

5  1   2  4  3

5  5  1  1  1  1
1  1  5  2  2  2
2  2  2  5  3 3
4  3  3  3  5  4
3  4  4  4  4  5
*/
void main()
{
int a[5],i,j;
clrscr();

for(i=0;i<5;i++)
{
cout<<“Enter the value:”;
cin>>a[i];
}
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}

}

for(int k=0;k<5;k++)
{
cout<<a[k];
}

cout<<endl;

}
for(i=0;i<5;i++)
{
cout<<a[i];
}

getch();
}

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.