Skip to content

Commit

Permalink
Add bubble sort
Browse files Browse the repository at this point in the history
  • Loading branch information
R-SE committed Feb 23, 2021
1 parent d20a7f2 commit 21c48cf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sort/bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <vector>
#include "../utils/helpers.h"

void bubble_sort(std::vector<int> &nums)
{
for (size_t i = 0; i < nums.size(); i++)
{
for (size_t j = 1; j < nums.size() - i; j++)
{
if (nums[j] < nums[j - 1])
{
int temp = nums[j];
nums[j] = nums[j - 1];
nums[j - 1] = temp;
}
}
}
}

int main()
{
std::vector<int> nums{6, 9, -3, 20, 55, 2, 11, 13};
bubble_sort(nums);
print_nums(nums);
}

0 comments on commit 21c48cf

Please sign in to comment.