Skip to content

Commit

Permalink
Bubble-Sort-Using-recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamAher30 committed Dec 27, 2023
1 parent 6502f34 commit 58bd5c4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions C++/Recursion/recursion_bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
void bubble(vector<int> &arr, int length)
{
if(length == 1) return ;
int didswap = 0;
for(int i = 0 ; i < length-1; i++)
{
if(arr[i] > arr[i+1])
{
swap(arr[i],arr[i+1]);
didswap = 1;
}
}
if(didswap == 0) return;

bubble(arr,--length);

}

int main()
{
vector<int> arr = {100, 23, 47, 99, 9, 25};
bubble(arr,arr.size());


for (auto it : arr)
{
cout << it << endl;
}
return 0;
}

0 comments on commit 58bd5c4

Please sign in to comment.