示例#1
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.QuickSort(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)
	}
}
示例#2
0
func main() {
	flag.Parse()
	fmt.Println("inFile = ", inFile, "outFile = ", outFile, "algorithm = ",
		algorithm)

	values, err := readValues(inFile)

	if err == nil {
		startTime := time.Now()
		switch algorithm {
		case "qsort":
			qsort.QuickSort(values)
		case "bubblesort":
			bubblesort.BubbleSort(values)
		case "mergesort":
			mergesort.MergeSort(values)
		case "mergesortp":
			mergesortp.MergeSortParallel(values)
		case "mergesortp2":
			mergesortp2.MergeSortParallel(values)
		default:
			{
				fmt.Println("Sorting algorithm", algorithm,
					"is either unknow or unsupported.")
			}
		}
		endTime := time.Now()
		fmt.Println("The sorting process costs", endTime.Sub(startTime),
			"to complete")
		writeValues(values, outFile)
	} else {
		fmt.Println(err)
	}
}