From 6487796e4b93301325ff5f738ecaf6a91ecdbbc9 Mon Sep 17 00:00:00 2001 From: hoang Date: Sun, 31 May 2020 20:44:03 +0700 Subject: [PATCH] bubblesort ignore last index --- c2-m1/bubbleSort.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c2-m1/bubbleSort.go b/c2-m1/bubbleSort.go index b18dd89..e90acee 100644 --- a/c2-m1/bubbleSort.go +++ b/c2-m1/bubbleSort.go @@ -45,7 +45,7 @@ func Swap(pos *int, nextPos *int) { // BubbleSort implements sorting algorithm over a slice of // integer func BubbleSort(sli []int) []int { - for i := range sli { + for i := range sli[:len(sli)-1] { for j := range sli[:len(sli)-1-i] { if sli[j] > sli[j+1] { Swap(&sli[j], &sli[j+1])