⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 自动测试排序算法性能
💻 JAVA
字号:
package Mysort.Test;
import java.io.*;
import java.util.*;
import Mysort.*;
public class test
{
	public static void main(String[] args)  throws IOException
	{
        int sum, i, j=0, n=0,array_length;
    	char k = '3';
    	boolean flag=true;
    	M x;
    	j_sort xsort;
		System.out.println("                                  java实验                               ");		
		System.out.println("                            自动测试排序算法性能                         ");     
		do
		{
			if(flag)
			{
				System.out.println("-------------------------------------------------------------------------------");
				System.out.print("请输入数组的规模大小:");
			}
			else 
			System.out.println("已经退出!谢谢使用!");
			if (k != '3') break; //控制是否退出
			do
			{
				array_length=0;
				j=System.in.read();
				while((j!=32)&&(j!=13))
				{
					array_length=array_length*10+j-48;
					j=System.in.read();
				}
			}while(j!=13);
			System.in.read();   //消除回车键
			int[] a = new int[array_length];
    	    int[] b = new int[array_length];
			System.out.print("请输入数组元素(不多于100个元素,如10 9 8):");
			do   //输入数组各元素的值          
			{
				sum = 0;
				j = System.in.read();
				while ((j!=32)&&(j!=13))     //空格的判断和回车的判断
				{
					sum = sum * 10 + j - 48;   //转化为整数
					j = System.in.read();
				}
				a[n] = sum;
				n++;
			} while (j != 13);       //回车的判断
			//n--;                //数组实际个数
			System.in.read();   //消除回车键
			do   //排序
			{
				System.out.print("选择(0-选择法 1-冒泡法 2-选择法 3-重输数组 按其他键退出!):");
				k = (char)System.in.read();//选择哪种排序
				System.in.read();   //消除回车键
				if ((k != '0') && (k != '1') && (k != '2')) break;//控制是否排序
				 
				for (int s = 0; s < n; s++) b[s] = a[s]; //保存数组a到数组b
				switch(k)
				{
					case '0':xsort=new xuanzhe_sort(a,n);
					         x=xsort.dosort();
 					         xsort.output();
 					         System.out.println(x); 
					         break;
				 	case '1':xsort=new maopao_sort(a,n);
					         x=xsort.dosort();
					         xsort.output();
					         System.out.println(x); 
					         break;
					case '2':xsort=new charu_sort(a,n);
					         x=xsort.dosort();
					         xsort.output();
					         System.out.println(x);
					         break;		
				}
				for (int s = 0; s < n; s++) a[s] = b[s]; //恢复数组a原先的内容
			} while (true);
			if(k!='3')flag = false;
			System.in.read();//消除回车键
		} while (true);

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -