comparison.java
来自「sorting,分类的几种常见的java实现」· Java 代码 · 共 35 行
JAVA
35 行
package sorting_yanrui;
import java.util.Random;
import java.util.Scanner;
public class Comparison {
static InsertSorting insert;
static HeapSorting heap;
static QuickSorting quick;
static ShellSorting shell;
public void main(String []args)
{ System.out.println("Input the number of digits to be sorted");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
int[] a = null;
for(int j=0;j<i;j++)
{Random rand = new Random();
a[j]= rand.nextInt(i);
}
int length=a.length;
long t1=insert.insertSorting(a,length);
long t2=heap.heapsort(a, length);
long t3=quick.QuickSorting(a, 0, length-1);
long t4=shell.shellsort(a, length);
System.out.println("The time cost of insertsorting is"+t1);
System.out.println("The time cost of heapsorting is"+t2);
System.out.println("The time cost of quicksorting is"+t3);
System.out.println("The time cost of shellsorting is"+t4);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?