Пример #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)
		case "mergesort":
			values = mergesort.MergeSort(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()

	if infile != nil {
		fmt.Println("infile=", *infile, ",  outfile=", *outfile, ",  algorithm=", *algorithm)
		values, err := readValues(*infile)
		if err == nil {
			fmt.Println("Read values:", values)
		} else {
			fmt.Println(err)
			return
		}
		t1 := time.Now()
		if *algorithm == "qsort" {
			qsort.QuickSort(values)
		} else if *algorithm == "bubblesort" {
			bubblesort.BubbleSort(values)
		} else {
			fmt.Println("Sorting algorithm", *algorithm, "is either unknown or unsupported.")
		}
		t2 := time.Now()
		fmt.Println("The sorting process costs", t2.Sub(t1), "to complete.")

		err = writeValues(values, *outfile)
		if err == nil {
			fmt.Println("Write values:", values)
		} else {
			fmt.Println(err)
			return
		}
	}
}
Пример #3
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 unkonw or unsupported.")
		}
		t2 := time.Now()
		fmt.Println(*algorithm, "算法耗时:", t2.Sub(t1))

		writeValues(values, *outfile)
	} else {
		fmt.Println(err)
	}
}
Пример #4
0
func main() {
	flag.Parse()

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

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

	} else {
		fmt.Println("Read values", values)
		t1 := time.Now()

		switch *algorithm {
		case "qsort":
			{
				qsort.QuickSort(values)
			}
		case "bubblesort":
			{
				bubblesort.BubbleSort(values)
			}
		default:
			fmt.Println("Sorting algorithm", *algorithm, "is either unknown orunsupported.")
		}

		t2 := time.Now()
		fmt.Println("The sorting process takes", t2.Sub(t1), "to complete.")
		err := writeValues(values, *outfile)
		fmt.Println("Write values", values)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
	}

}