Esempio n. 1
0
func main() {
	data := []int{4, 10, 3, 1, 100, 50, 23, 4, 4, 10, 23, 60, 12, 6, 105, 500, 10, 1, 30, 20}
	fmt.Printf("UNSORTED:\n%o\n", data)
	fmt.Printf("MERGESORT:\n%o\n", mergesort.Sort(data))

	data = []int{4, 10, 3, 1, 100, 50, 23, 4, 4, 10, 23, 60, 12, 6, 105, 500, 10, 1, 30, 20}
	fmt.Printf("QUICKSORT:\n%o\n", quicksort.Sort(data))
	data = []int{4, 10, 3, 1, 100, 50, 23, 4, 4, 10, 23, 60, 12, 6, 105, 500, 10, 1, 30, 20}
	fmt.Printf("HEAPSORT :\n%o\n", heapsort.Sort(data))
}
Esempio n. 2
0
func TestSort(t *testing.T) {

	var a = []int{3, 5, 7, 1, 2, 4, 6}
	fmt.Println("Input: ", a)
	quicksort.Sort(a)
	fmt.Println("Output: ", a)

	for i := 1; i < len(a); i++ {
		if a[i] < a[i-1] {
			t.Error("Not sorted")
			fmt.Println(a)
		}
	}
}