예제 #1
0
파일: main.go 프로젝트: jvillasante/algs4
/*************************************************************************
 *  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)
}
예제 #2
0
파일: main.go 프로젝트: jvillasante/algs4
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()
}