Ejemplo n.º 1
0
func TestInsertionSort(t *testing.T) {
	var b = []float64{'S', 'O', 'R', 'T', 'e', 'X', 'A', 'M', 'P', 'L', 'E'}
	var s InsertionSort

	a := algorithms.NewDoubleSlice(b)

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

	s.Sort(a)

	for i := 0; i < len(a); i++ {
		fmt.Printf("%f ", a[i])
	}
	fmt.Printf("\n")
	fmt.Printf("a[] is sored? %v\n", s.IsSorted(a))
}
Ejemplo n.º 2
0
func TestMinHeap(t *testing.T) {
	M := 5
	a := algorithms.NewDoubleSlice(b)
	minPQ := NewMinHeap(M + 1)
	for i := 0; i < len(a); i++ {
		minPQ.Push(a[i])
		if minPQ.Size() > M {
			minPQ.Pop()
		}
	}

	var stack container.Stack
	for !minPQ.IsEmpty() {
		stack.Push(minPQ.Pop().Value.(algorithms.Double))
	}

	iter := stack.Iterator()
	for iter.HasNext() {
		fmt.Printf("%f\n", iter.Next().Value.(algorithms.Double))
	}
}