Skip to content

Commit

Permalink
added insertionsort.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AshiSinha18 authored Oct 27, 2017
1 parent 4848ddd commit 689228d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions insertionsort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"algoutils"
)

func insertionSort(array []int) {
for i := 1; i < len(array); i++ {
for j := i; j > 0 && array[j] < array[j - 1]; j-- {
algoutils.Swap(array, j, j - 1)
}
}
}

func main() {

array := []int{1, 6, 2, 4, 9, 0, 5, 3, 7, 8}
fmt.Println("Unsorted array: ", array)
insertionSort(array)
fmt.Println("Sorted array: ", array)
}

0 comments on commit 689228d

Please sign in to comment.