all repos

scratch @ cafea31

⭐ me doing recreational ~~drugs~~ programming
2 files changed, 27 insertions(+), 0 deletions(-)
algos: bubble sort why not
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-04-13 16:53:38 +0300
Change ID: svoloypxqwswrvlqtmrssztyorsuxqrl
Parent: 22fce74
A algos/bubblesort.go
···
                
                1
                +package algos

              
                
                2
                +

              
                
                3
                +func BubbleSort(inp []int) {

              
                
                4
                +	for i := 0; i < len(inp); i++ {

              
                
                5
                +		for j := 0; j < len(inp)-1-i; j++ {

              
                
                6
                +			if inp[j] > inp[j+1] {

              
                
                7
                +				inp[j], inp[j+1] = inp[j+1], inp[j]

              
                
                8
                +			}

              
                
                9
                +		}

              
                
                10
                +	}

              
                
                11
                +}

              
A algos/bubblesort_test.go
···
                
                1
                +package algos

              
                
                2
                +

              
                
                3
                +import (

              
                
                4
                +	"reflect"

              
                
                5
                +	"testing"

              
                
                6
                +)

              
                
                7
                +

              
                
                8
                +func TestBubleSort(t *testing.T) {

              
                
                9
                +	inp := []int{9, 3, 7, 4, 69, 420, 42}

              
                
                10
                +	out := []int{3, 4, 7, 9, 42, 69, 420}

              
                
                11
                +

              
                
                12
                +	BubbleSort(inp)

              
                
                13
                +	if !reflect.DeepEqual((inp), out) {

              
                
                14
                +		t.Fatalf("i fucked up, %#v, %#v\n", inp, out)

              
                
                15
                +	}

              
                
                16
                +}