func TestBinarySearchTree(t *testing.T) {
	var b = []int{'S', 'E', 'A', 'R', 'C', 'H', 'E', 'X', 'A', 'M', 'P', 'L', 'E'}
	var st SymbolTable

	a := algorithms.NewIntegerSlice(b)

	st = &BinarySearchTree{}

	for i := 0; i < len(a); i++ {
		st.Set(a[i], i)
	}

	iter := st.Keys()
	for iter.HasNext() {
		key := iter.Next().Value.(algorithms.Integer)
		fmt.Printf("%c %d\n", key, st.Get(key))
	}
}
示例#2
0
func TestMergeSort(t *testing.T) {
	var b = []int{'S', 'O', 'R', 'T', 'e', 'X', 'A', 'M', 'P', 'L', 'E'}
	var s MergeSort

	a := algorithms.NewIntegerSlice(b)

	for i := 0; i < len(a); i++ {
		fmt.Printf("%c ", a[i])
	}
	fmt.Printf("\n")

	s.Sort(a)

	for i := 0; i < len(a); i++ {
		fmt.Printf("%c ", a[i])
	}
	fmt.Printf("\n")
	fmt.Printf("a[] is sored? %v\n", s.IsSorted(a))
}