Skip to content

Commit ea046a4

Browse files
authored
Merge pull request thuva4#319 from Jaernbrand/master
Add Ruby insertion sort
2 parents 20f9759 + 6ae7e4c commit ea046a4

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,4 @@ Unfortunately, sometimes the bug can be only reproduced in your project or in yo
146146
- [BurnzZ](https://github.com/BurnzZ)
147147
- [FernandaOchoa](https://github.com/FernandaOchoa)
148148
- [npcoder2k14](https://github.com/npcoder2k14)
149+
- [Jaernbrand](https://github.com/Jaernbrand)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
def insertion_sort(input)
3+
input.size.times do |i|
4+
j = i-1
5+
curr_element = input[i]
6+
while j >= 0 && input[j] > curr_element do
7+
input[j+1] = input[j]
8+
j -= 1
9+
end
10+
input[j+1] = curr_element
11+
end
12+
end
13+
14+
input = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0, 5]
15+
insertion_sort(input)
16+
puts input

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Floyd'sAlgorithm | :+1: | :+1: | | | :+1: | | | |
3232
GreatestCommonDivisor | :+1: |:+1:| :+1: | :+1: | :+1: | | | |
3333
HammingDistance | :+1: | :+1: | | :+1: | | :+1: | :+1: | |
3434
HeapSort | :+1: | :+1: | | | :+1: | :+1: | :+1: | | :+1:
35-
HistogramEqualization | :+1: | | | | | | | |
36-
InsertionSort | :+1: | :+1: | :+1: | :+1: | :+1: | | :+1: | :+1: |
35+
HistogramEqualization | :+1: | | | | | | | |
36+
InsertionSort | :+1: | :+1: | :+1: | :+1: | :+1: | | :+1: | :+1: | :+1:
3737
Inverse Fast Fourier Transform | | | | | :+1: | | | |
3838
Johnson algorithm | :+1: | :+1: | | | :+1: | | | |
3939
Kadane's algorithm | :+1: | :+1: | | :+1: | :+1: | :+1: | :+1: | |

0 commit comments

Comments
 (0)