Skip to content

Commit 19a29aa

Browse files
author
Bhrigu Kansra
authored
Merge pull request #155 from nitish14kumr/master
Recursive Bubble Sort
2 parents 3b7d718 + c78b7a1 commit 19a29aa

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
void bubbleSort(int arr[], int n)
4+
{
5+
if (n == 1)
6+
return;
7+
for (int i=0; i<n-1; i++)
8+
if (arr[i] > arr[i+1])
9+
swap(arr[i], arr[i+1]);
10+
bubbleSort(arr, n-1);
11+
}
12+
13+
void printArray(int arr[], int n)
14+
{
15+
for (int i=0; i < n; i++)
16+
printf("%d ", arr[i]);
17+
printf("\n");
18+
}
19+
20+
int main()
21+
{
22+
int arr[] = {64, 34, 25, 12, 22, 11, 90};
23+
int n = sizeof(arr)/sizeof(arr[0]);
24+
bubbleSort(arr, n);
25+
printf("Sorted array : \n");
26+
printArray(arr, n);
27+
return 0;
28+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
def insertionSort(alist):
2-
for index in range(1,len(alist)):
3-
4-
currentvalue = alist[index]
5-
position = index
6-
7-
while position>0 and alist[position-1]>currentvalue:
8-
alist[position]=alist[position-1]
9-
position = position-1
10-
11-
alist[position]=currentvalue
12-
13-
alist = [54,26,93,17,77,31,44,55,20]
14-
insertionSort(alist)
15-
print(alist)
1+
def insertionSort(alist):
2+
for index in range(1,len(alist)):
3+
4+
currentvalue = alist[index]
5+
position = index
6+
7+
while position>0 and alist[position-1]>currentvalue:
8+
alist[position]=alist[position-1]
9+
position = position-1
10+
11+
alist[position]=currentvalue
12+
13+
alist = [54,26,93,17,77,31,44,55,20]
14+
insertionSort(alist)
15+
print(alist)

contributors.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
39. [Sanka Mohottala](https://github.com/sankamohottala)
4242
40. [Riya Singh](https://github.com/riya24899)
4343
41. [Sarthak gupta](https://github.com/sarthak-g)
44-
42. [Your Name](https://github.com/yourusername)
44+
42. [Nitish Kumar](https://github.com/nitish14kumr)
4545
43. [Seemant Aggarwal] (https://github.com/seemantaggarwal)
4646
44. [Vibhav Tiwari] (https://github.com/VibhavTiwari)
47+
45. [Your Name](https://github.com/yourusername)

0 commit comments

Comments
 (0)