mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Bubble Sort
This commit is contained in:
parent
a590fe1beb
commit
11e42c9f43
37
BubbleSort.cpp
Normal file
37
BubbleSort.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
//Bubble Sort
|
||||
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int Array[6];
|
||||
cout<<"\nEnter any 6 Numbers for Unsorted Array : ";
|
||||
|
||||
//Input
|
||||
for(int i=0; i<6; i++)
|
||||
{
|
||||
cin>>Array[i];
|
||||
}
|
||||
|
||||
//Bubble Sorting
|
||||
for(int i=0; i<6; i++)
|
||||
{
|
||||
for(int j=0; j<5; j++)
|
||||
{
|
||||
if(Array[j]>Array[j+1])
|
||||
{
|
||||
int temp=Array[j];
|
||||
Array[j]=Array[j+1];
|
||||
Array[j+1]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Output
|
||||
cout<<"\nSorted Array : ";
|
||||
for(int i=0; i<6; i++)
|
||||
{
|
||||
cout<<Array[i]<<"\t";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user