2016-07-16 18:56:48 +08:00
|
|
|
//Bubble Sort
|
|
|
|
|
|
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-05-27 20:40:04 +08:00
|
|
|
int n;
|
|
|
|
cin >> n;
|
|
|
|
int Array[n];
|
2016-07-16 18:56:48 +08:00
|
|
|
cout<<"\nEnter any 6 Numbers for Unsorted Array : ";
|
2017-05-27 20:40:04 +08:00
|
|
|
|
2016-07-16 18:56:48 +08:00
|
|
|
//Input
|
2017-05-27 20:40:04 +08:00
|
|
|
for(int i=0; i<n; i++)
|
2016-07-16 18:56:48 +08:00
|
|
|
{
|
|
|
|
cin>>Array[i];
|
|
|
|
}
|
2017-05-27 20:40:04 +08:00
|
|
|
|
2016-07-16 18:56:48 +08:00
|
|
|
//Bubble Sorting
|
2017-05-27 20:40:04 +08:00
|
|
|
for(int i=0; i<n; i++)
|
2016-07-16 18:56:48 +08:00
|
|
|
{
|
2017-05-27 20:40:04 +08:00
|
|
|
for(int j=0; j<n-1; j++)
|
2016-07-16 18:56:48 +08:00
|
|
|
{
|
|
|
|
if(Array[j]>Array[j+1])
|
|
|
|
{
|
|
|
|
int temp=Array[j];
|
|
|
|
Array[j]=Array[j+1];
|
|
|
|
Array[j+1]=temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 20:40:04 +08:00
|
|
|
|
2016-07-16 18:56:48 +08:00
|
|
|
//Output
|
|
|
|
cout<<"\nSorted Array : ";
|
2017-05-27 20:40:04 +08:00
|
|
|
for(int i=0; i<n; i++)
|
2016-07-16 18:56:48 +08:00
|
|
|
{
|
|
|
|
cout<<Array[i]<<"\t";
|
|
|
|
}
|
|
|
|
}
|