04/15/2020发表Code算法分析入门系列(一) 排序算法排序算法main函数代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970public static void main(String[] args) { int max = 10; System.out.println("插入排序-------------------------------------"); int[] num = randomCreate(max); printResult(num); Long bt = System.nanoTime(); int[] temp1 = insertSort(num); Long et = System.nanoTime(); System.out.println("排序用时:" + (et - bt + "")); printResult(temp1); System.out.println("合并排序-------------------------------------"); int[] temp4 = randomCreate(max); printResult(temp4); Long bt2 = System.nanoTime(); mergeSort(temp4); Long et2 = System.nanoTime(); System.out.println("排序用时:" + (et2 - bt2 + "")); printResult(temp4); System.out.println("快速排序-------------------------------------"); int[] temp5 = randomCreate(max); printResult(temp5); Long bt3 = System.nanoTime(); quickSort(temp5, 0, temp5.length - 1, false); Long et3 = System.nanoTime(); System.out.println("排序用时:" + (et3 - bt3 + "")); printResult(temp5); System.out.println("随机化快速排序--------------------------------"); int[] temp9 = randomCreate(max); printResult(temp9); Long bt7 = System.nanoTime(); quickSort(temp9, 0, temp9.length - 1, true); Long et7 = System.nanoTime(); System.out.println("排序用时:" + (et2 - bt2 + "")); printResult(temp9); System.out.println("桶排序---------------------------------------"); int[] temp6 = randomCreate(max); printResult(temp6); Long bt4 = System.nanoTime(); temp6 = bucketSort(temp6, max); Long et4 = System.nanoTime(); System.out.println("排序用时:" + (et4 - bt4 + "")); printResult(temp6); System.out.println("计数排序-------------------------------------"); int[] temp7 = randomCreate(max); printResult(temp7); Long bt5 = System.nanoTime(); temp7 = countSort(temp7); Long et5 = System.nanoTime(); System.out.println("排序用时:" + (et5 - bt5 + "")); printResult(temp7); System.out.println("基数排序-------------------------------------"); int[] temp8 = randomCreate(max); printResult(temp8); Long bt6 = System.nanoTime(); radixSort(temp8, (max + "").length()); Long et6 = System.nanoTime(); System.out.println("排序用时:" + (et6 - bt6 + "")); printResult(temp8); System.out.println("---------------------------------------------");}阅读更多
08/12/2019发表Code散列表相关的几个算法根据算法图解一书写的两个算法:广度优先算法以及狄克斯特拉算法: 散列表散列表在Python中也称作字典,通常的定义方式为: name = dict()阅读更多