📄 testsearchsort.java
字号:
import java.io.*;
public class TestSearchSort
{
short[] testArray;
public TestSearchSort()
{
testArray = new short[10];
testSearches();
testSorts();
}
public void resetArray()
{
testArray[0] = 23;
testArray[1] = 4;
testArray[2] = 15;
testArray[3] = 37;
testArray[4] = 7;
testArray[5] = 19;
testArray[6] = 1;
testArray[7] = 9;
testArray[8] = 31;
testArray[9] = 12;
}
public void testSearches()
{
System.out.println("\nStart testSearches");
resetArray();
System.out.println("7 is in location " + Searches.linSearch(testArray, (short)7));
System.out.println("12 is in location " + Searches.linSearch(testArray, (short)12));
System.out.println("9 is in location " + Searches.linSearch(testArray, (short)9));
System.out.println("2 is in location " + Searches.linSearch(testArray, (short)2));
Sorts.mergeSort(testArray);
System.out.println(" After sort testArray is ");
for (int i=0; i<testArray.length; i++)
System.out.print(testArray[i] + " ");
System.out.println(" ");
System.out.println("7 is in location " + Searches.linSearch(testArray, (short)7));
System.out.println("12 is in location " + Searches.linSearch(testArray, (short)12));
System.out.println("9 is in location " + Searches.linSearch(testArray, (short)9));
System.out.println("2 is in location " + Searches.linSearch(testArray, (short)2));
System.out.println("7 is in location " + Searches.binarySearch(testArray, (short)7));
System.out.println("12 is in location " + Searches.binarySearch(testArray, (short)12));
System.out.println("9 is in location " + Searches.binarySearch(testArray, (short)9));
System.out.println("2 is in location " + Searches.linSearch(testArray, (short)2));
BasicBox[] boxArray = new BasicBox[5];
BasicBox box1 = new BasicBox(1, 11, 21);
boxArray[0] = box1;
BasicBox box2 = new BasicBox(2, 12, 22);
boxArray[1] = box2;
BasicBox box3 = new BasicBox(3, 13, 23);
boxArray[2] = box3;
BasicBox box4 = new BasicBox(4, 14, 24);
boxArray[3] = box4;
BasicBox box5 = new BasicBox(5, 15, 25);
boxArray[4] = box5;
System.out.println("box3 is in " + Searches.linSearch(boxArray, box3));
BasicBox testbox = new BasicBox(3, 13, 23);
System.out.println("testbox3 is in " + Searches.linSearch(boxArray, testbox));
System.out.println("box5 is in " + Searches.linSearch(boxArray, box5));
testbox = new BasicBox(5, 15, 25);
System.out.println("testbox5 is in " + Searches.linSearch(boxArray, testbox));
BetterBasicBox[] bboxArray = new BetterBasicBox[5];
BetterBasicBox bbox1 = new BetterBasicBox(1, 11, 21);
bboxArray[0] = bbox1;
BetterBasicBox bbox2 = new BetterBasicBox(2, 12, 22);
bboxArray[1] = bbox2;
BetterBasicBox bbox3 = new BetterBasicBox(3, 13, 23);
bboxArray[2] = bbox3;
BetterBasicBox bbox4 = new BetterBasicBox(4, 14, 24);
bboxArray[3] = bbox4;
BetterBasicBox bbox5 = new BetterBasicBox(5, 15, 25);
bboxArray[4] = bbox5;
BetterBasicBox testbbox = new BetterBasicBox(3, 13, 23);
System.out.println("testbbox3 is in " + Searches.linSearch(bboxArray, testbbox));
testbbox = new BetterBasicBox(5, 15, 25);
System.out.println("testbbox5 is in " + Searches.linSearch(bboxArray, testbbox));
testbbox = new BetterBasicBox(5, 1, 25);
System.out.println("testbbox is in " + Searches.linSearch(bboxArray, testbbox));
System.out.println("\nEnd Searches");
}
public void testSorts()
{
System.out.println("\nStart sorts");
resetArray();
Sorts.mergeSort(testArray);
System.out.println("The result from mergeSort: " + Sorts.display(testArray) + "\n");
resetArray();
Sorts.mergeSelectSort(testArray);
System.out.println("The result from mergeSelectSort " + Sorts.display(testArray) + "\n");
resetArray();
Sorts.selectSort(testArray, 0, testArray.length-1);
System.out.println("The result from selectSort " + Sorts.display(testArray) + "\n");
System.out.println("End of sort");
}
public static void main(String args[])
{
new TestSearchSort();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -