Ejemplo n.º 1
0
func main() {
	flag.Parse()

	if infile != nil {
		fmt.Println("infile =", *infile, ", outfile =", *outfile, ", algorithm =", *algorithm)
	}

	values, err := readValue(*infile)
	if err != nil {
		fmt.Println(err)
		return
	}

	switch *algorithm {
	case "bubblesort":
		bubblesort.BubbleSort(values)
	case "qsort":
		qsort.Qsort(values)
	default:

	}

	fmt.Println("Write to file:", values)
	err = writeValue(*outfile, values)
	if err != nil {
		fmt.Println(err)
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	if infile != nil {
		fmt.Println("infile =", *infile, "outfile =", *outfile, "algorithm =", *algorithm)
	}

	values, err := readValues(*infile)
	if err == nil {
		t1 := time.Now()
		switch *algorithm {
		case "qsort":
			qsort.Qsort(values)
		case "bubblesort":
			bubblesort.Bubblesort(values)
		default:
			fmt.Println("Sorting algorithm", *algorithm, "is either unknown or unsupported")

		}
		t2 := time.Now()
		fmt.Println("The sorting process costs", t2.Sub(t1), "to complete")
		writeValues(values, *outfile)
	} else {
		fmt.Println(err)
	}
}