Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit ca6480c

Browse files
Merge pull request #705 from alvinma/alvinma_RecursiveBubbleSort
Recursive Bubble Sort Implementation in C++
2 parents e21f9b8 + dd2de3e commit ca6480c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

cpp/alvinma_RecursiveBubbleSort.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
void bubblesort(int array[],int size){
5+
if (size == 1){
6+
return;
7+
}
8+
9+
int temp;
10+
for(int i = 0; i < size-1; i++){
11+
if(array[i] > array[i+1]){
12+
temp = array[i];
13+
array[i] = array[i+1];
14+
array[i+1] = temp;
15+
}
16+
}
17+
18+
bubblesort(array, size-1);
19+
}
20+
21+
int main()
22+
{
23+
int array[]={1,34,56,78,89,23,83,28,90,37};
24+
int size=sizeof(array)/sizeof(array[0]);
25+
26+
cout<<"Original Array is ";
27+
for(int i=0;i<size;i++){
28+
cout<<array[i]<<" ";
29+
}
30+
cout<<endl;
31+
32+
bubblesort(array,size);
33+
34+
cout<<"Sorted Array is ";
35+
for(int i=0;i<size;i++){
36+
cout<<array[i]<<" ";
37+
}
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)