Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"math"
)
// 二分木を確認するための補助関数
// 二桁になると表示のバランスが崩れるのでdebug用
// 本関数を使用しない場合はmathパッケージをimportしなくてよい
package main
import (
"fmt"
)
// 中間値を返す
func Med3(x, y, z int) int {
if x < y {
if y < z {
package main
import (
"fmt"
"reflect"
)
func main() {
a := []int{1, 2, 3}
b := []int{2, 1, 3} // a != b
package main
import (
"fmt"
"sort"
)
func main() {
a := []int{2, 3, 1, 2, 5}
package MySort
func BubbleSort(a []int) {
for i := 0; i < len(a) - 1; i++ {
for j := 0; j < len(a) - i - 1; j++ {
if a[j] > a[j + 1] {
a[j], a[j + 1] = a[j + 1], a[j]
}
}
}
package MySort
import (
"testing"
"reflect"
"sort"
)
// テストパターン
var SortTests = [][]int {
package MySort
// テストパターン
var SortTests = [][]int {
{2, 1, 3, 5, 4},
{1, 2, 3, 4, 5},
{1, 3, 4, 5, 2, 1},
{1, 0, 2},
{1, 1, 1, 1, 1, 1, 1, 1},
}
package MySort
import (
"testing"
"reflect"
"sort"
)
func TestBubbleSort(t *testing.T) {
for _, actual := range SortTests {
package MySort
import (
"testing"
)
func BenchmarkBubbleSort(b *testing.B) {
for i:= 0; i <b.N; i++ {
BubbleSort(a)
}
package MySort
import (
"testing"
)
func BenchmarkBubbleSort(b *testing.B) {
for i:= 0; i <b.N; i++ {
BubbleSort(a)
}