This repository was archived by the owner on Oct 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from AmodhShenoy/master
Add Bubble Sort
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include<iostream.h> | ||
#include<conio.h> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n,temp; | ||
int a[200]; | ||
while(true) | ||
{ | ||
cout<<"Enter the number of elements"<<endl; | ||
cin>>n; | ||
if(n<=200) | ||
{ | ||
cout<<"Enter the elements"<<endl; | ||
for(int i=0;i<n;i++) | ||
cin>>a[i]; | ||
for(int j=n-1;j>0;j--) | ||
{ | ||
for(int k=0;k<j;k++) | ||
{ | ||
if(a[j]>a[j+1]) | ||
{ | ||
temp=a[j]; | ||
a[j]=a[j+1]; | ||
a[j+1]=temp; | ||
} | ||
} | ||
} | ||
cout<<"The sorted elements are:"; | ||
for(int l=0;l<n;l++) | ||
cout<<" "<<a[l]; | ||
break; | ||
} | ||
else | ||
cout<<"Number of elements exceeds limit(200). Please try again."<<endl; | ||
} | ||
return 0; | ||
} | ||
|