Академический Документы
Профессиональный Документы
Культура Документы
import java.util.*;
//**************************************************************
//**************************************************************
//**************************************************************
while (!sorted)
{
for (x = 0; x <= z; x++)
if (intarray[x] > intarray[y]) y = x;
temp = intarray[z];
//final value is copied
intarray[z] = intarray[y];
//largest array value copied to final spot in array
intarray[y] = temp;
z--;
y = 0;
if (z == 0) sorted = true;
if (oneten * mten == z && ten) {
System.out .println(100 - (mten*10) + "%");
mten--;}
if (onehun * mhun == z && hun) {
System.out .println(100 - (mhun) + "%");
mhun--;}
}
long endtime = System.nanoTime();
long timetotal = (long)(endtime - starttime);
long seconds = timetotal/1000000000;
timetotal = timetotal - (seconds * 1000000000);
System.out .println("Sorting took " + seconds + "s, " +
timetotal/1000000.0 + " ms.");
} //end of selectionSort()
//**************************************************************
} // end of while
//**************************************************************
//**************************************************************
//**************************************************************
reload(intarray);
while(!done)
{
select = menu();
switch (select) {
//**************************************************** LINEAR SEARCH RESULTS
case 1:
location = linearSearch(intarray);
if (location != -1)
{
if (sorted)
{
if (location > 0)
{
System.out .print("\nInteger found at the
following location(s): " + location);
if (intarray[location - 1] == intarray[size - 1])
{
for(int x = location; x < size; x++) {
location++;
System.out .print(", " + location);
}
} //end of if
else {
for(int z = location - 1; intarray[z] == intarray[z+1];z++)
{
location++;
System.out .print(", " + location);
}
} //end of else
System.out .println();
}//if(location > 0)
} //if (sorted)
else {
System.out .println("\nInteger first found at
location " + location + " in the unsorted
array. ");
System.out .println("The integer may exist in other
locations.");
} //else
} //if (location != 1)
else {
for(int z = location - 1; intarray[z] == intarray[z+1];z++)
{
location++;
System.out .print(", " + location);
}
} //end of else
System.out .println();
}
break;
//*****************************************************************************
case 5:
reload(intarray);
break;
case 0:
done = true;
break;
default:
System.out .println("Invalid Entry");
break;
} //end of switch case
} //end of while loop
} //end of main
} //end of class