Skip to content

Commit

Permalink
Merge pull request #27 from Manvi07/master
Browse files Browse the repository at this point in the history
Added bubble sort in C++
  • Loading branch information
i-vishi authored Oct 2, 2018
2 parents 0569aae + 0da469b commit da0b595
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Sorting/bubbleSort/bubble_sort.cpp
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;
}

0 comments on commit da0b595

Please sign in to comment.