This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
// 二分木を確認するための補助関数 | |
// 二桁になると表示のバランスが崩れるのでdebug用 | |
// 本関数を使用しない場合はmathパッケージをimportしなくてよい |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
// 中間値を返す | |
func Med3(x, y, z int) int { | |
if x < y { | |
if y < z { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
func main() { | |
a := []int{1, 2, 3} | |
b := []int{2, 1, 3} // a != b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
func main() { | |
a := []int{2, 3, 1, 2, 5} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MySort | |
import ( | |
"testing" | |
"reflect" | |
"sort" | |
) | |
// テストパターン | |
var SortTests = [][]int { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MySort | |
import ( | |
"testing" | |
"reflect" | |
"sort" | |
) | |
func TestBubbleSort(t *testing.T) { | |
for _, actual := range SortTests { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MySort | |
import ( | |
"testing" | |
) | |
func BenchmarkBubbleSort(b *testing.B) { | |
for i:= 0; i <b.N; i++ { | |
BubbleSort(a) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MySort | |
import ( | |
"testing" | |
) | |
func BenchmarkBubbleSort(b *testing.B) { | |
for i:= 0; i <b.N; i++ { | |
BubbleSort(a) | |
} |