Skip to content

Commit

Permalink
Merge pull request #14 from AndreiG23/master
Browse files Browse the repository at this point in the history
Added bubble sort in cpp at issue #1
  • Loading branch information
Harshita-Kanal authored Oct 2, 2020
2 parents bb8150c + 6144287 commit e9f1d05
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Cpp-bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <vector>

using namespace std;

vector<int> bubble_sort(vector<int> arr)
{
int n=arr.size();
for (int i = 0; i < n-1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (arr[i] > arr[j])
{
int aux = arr[j];
arr[j] = arr[i];
arr[i] = aux;
}
}
}
return arr;
}

int main()
{

vector<int> arr = { 6, 3, 7, 1, 12, 5, 43, 21 ,8 ,9 };

arr=bubble_sort(arr);

for (int i = 0; i < arr.size(); i++)
cout << arr[i]<< ' ';
}

0 comments on commit e9f1d05

Please sign in to comment.