func main() { println("this is a sort test") flag.Parse() fmt.Printf("The flag input is wrong, num is %d, please input again\n", flag.NArg()) fmt.Println(*infile) if infile != nil { fmt.Println("infile =", *infile, "outfile =", *outfile, "algorithm =", *algorithm) } else { fmt.Println("please input the infile") return } 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("unknow method of sort") } t2 := time.Now() fmt.Println("sort algorithm", *algorithm, "costs", t2.Sub(t1), "to complete") writeValues(values, *outfile) } }
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) } }
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) return } t1 := time.Now() switch *algorithm { case "qsort": qsort.QuickSort(values) case "bubblesort": bubblesort.BubbleSort(values) default: fmt.Println("sort algorithm cannot recognized") } t2 := time.Now() fmt.Println("The sorting process costs", t2.Sub(t1), "to complete") fmt.Println("result: ", values) err1 := writeValues(values, *outfile) if err1 != nil { fmt.Println("writeFailed", err) } }
func main() { // 解析命令行参数 flag.Parse() values, err := readValues(*infile) if err == nil { fmt.Println("Read values:", values) switch *algorithm { case "bubblesort": bubblesort.BubbleSort(values) case "qsort": qsort.QuickSort(values) default: fmt.Println("Sorting algorithm", *algorithm, "is unknown.") } fmt.Println("Write values:", values) writeValues(values, *outfile) } else { fmt.Println(err) } }
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 or unsipported.") } t2 := time.Now() fmt.Println("Write values:", values) fmt.Println("The sorting process costs", t2.Sub(t1), "to complete") //将排序后的值写出 writeValues(values, *outfile) } }