Exemplo n.º 1
0
/*************************************************************************
 *  Data files:   http://algs4.cs.princeton.edu/21sort/tiny.txt
 *                http://algs4.cs.princeton.edu/21sort/words3.txt
 *
 *  Sorts a sequence of strings from standard input
 *
 *  % more tiny.txt
 *  S O R T E X A M P L E
 *
 *  % ./sort < tiny.txt
 *  A E E L M O P R S T X
 *
 *  % more words3.txt
 *  bed bug dad yes zoo ... all bad yet
 *
 *  % ./sort < words3.txt
 *  all bad bed bug dad ... yes yet zoo    [ one string per line ]
 *
 *************************************************************************/
func main() {
	a, _ := in.ReadAllStrings(os.Stdin)
	data := sort.StringSlice(a)

	// selection.Sort(data)
	// insertion.Sort(data)
	shell.Sort(data)
	if !sort.IsSorted(data) {
		panic("data not sorted!")
	}
	fmt.Println(data)
}
Exemplo n.º 2
0
func time(alg string, a []float64) float64 {
	data := sort.Float64Slice(a)
	timer := stopwatch.New()

	switch alg {
	case "Gosort":
		gosort.Sort(data)
	case "Insertion":
		insertion.Sort(data)
	case "Selection":
		selection.Sort(data)
	case "Shell":
		shell.Sort(data)
	default:
		panic("Unrecognized Algorithm")
	}

	return timer.ElapsedTime()
}