- Back to Home »
- C plus »
- Bubble Sorting
Posted by : Unknown
Wednesday, October 9, 2013
There's a lot of methods to sort an array.but here i discussed about Bubble Sorting.
Bubble Sorting
#include<iostream>#include<conio.h>
using namespace std;
int main()
{
int arr[10],temp;
cout<<"Enter The Elements in array";
for(int i=0; i<5;i++)
{
cout<<"Enter Element at index["<<i<<"]\t";
cin>>arr[i];
}
cout<<"\nArray before Sorting\n";
for(int i=0; i<5;i++)
{
cout<<arr[i]<<endl;
}
cout<<"\nArray After Sorting\n";
for(int i=0; i<5;i++)
for(int i=0; i<4;i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
for(int i=0; i<5;i++)
{
cout<<arr[i]<<endl;
}
getch();
}
I hope this is helpful for you.....