below is my code about a method regarding arrays.
The purpose of my program is to let the user input the length of the array.
and then insert numbers into the array, sort the numbers,
and let the user search the contents of the array.
my problem is i dont know how to apply them into a main method.
any tips on how to use them? can give me an example?
thanks in advance. I really need help.
public class Exer2
{
int listLength;
int[]list=new int[listLength];
public void insert1(int loc,int item)
{
list[loc]=item;
}
public void insert2(int item)
{
for(int x=0;x<=list.length;x++)
{
{
if(list[x]==0)
list[x]=item;
}
}
}
public static void selectionSort(int[] list,int listLength)
{
int index;
int smallestIndex;
int minIndex;
int temp;
for (index = 0; index < listLength - 1; index++)
{
smallestIndex = index;
for (minIndex = index + 1;
minIndex < listLength; minIndex++)
if (list[minIndex] < list[smallestIndex])
smallestIndex = minIndex;
temp = list[smallestIndex];
list[smallestIndex] = list[index];
list[index] = temp;
}
}
public static int seqOrderedSearch(int[] list,int listLength, int searchItem)
{
int loc;
boolean found = false;
for (loc = 0; loc < listLength; loc++){
if (list[loc] >= searchItem)
{
found = true;
break;
}
}
if (found){
if (list[loc] == searchItem)
return loc;
else
return -1;
}
else
return -1;
}
}