-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #27 from Manvi07/master
Added bubble sort in C++
- Loading branch information
Showing
1 changed file
with
33 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,33 @@ | ||
/* Bubble Sort implementation in C++ | ||
* Author : Manvi Gupta | ||
* Input : array length and elements | ||
* Output : Sorted array elements | ||
*/ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int n; | ||
|
||
void bubble_Sort(int a[]) | ||
{ | ||
|
||
for(int i=0; i<n-1; i++) | ||
for(int j=0; j<n-1-i; j++) | ||
if(a[j] > a[j+1]) | ||
{ | ||
swap(a[j+1], a[j]); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
cin >> n; | ||
int a[n]; | ||
for(int i=0; i<n; i++) | ||
cin >> a[i]; | ||
bubble_Sort(a); | ||
for (int i = 0; i < n; i++) { | ||
std::cout << a[i] << '\n'; | ||
} | ||
return 0; | ||
} |