search task
Started by lmc059, Jan 15 2008 01:09 PM
4 replies to this topic
#1
Posted 15 January 2008 - 01:09 PM
does anyone know where to start with this task im having some trouble getting to grips with java, i have uploaded the task.
|
|
|
#2
Posted 21 January 2008 - 09:20 AM
Not exactly what you need, but its close.
This is the sequential search code i use
[HIGHLIGHT="Java5"]public static int seqSearch (int[] list, int length, int search){
int loc;
for (loc = 0; loc < length; loc++)
if (list[loc] == search)
return loc;
return -1;
}[/HIGHLIGHT]
Tease might also come in handy
bubble sort:
[HIGHLIGHT="Java5"]public static void bubbleSort (int[] list, int length){
int temp, counter, index;
for (counter = 0; counter < length - 1; counter ++){
for (index = 0; index < length - 1 - counter; index++)
if (list[index] > list[index + 1]){
temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
}
}
}[/HIGHLIGHT]
Insertion Sort
[HIGHLIGHT="Java5"]public static void insertionSort (int[] list, int listLength){
int firstOutOfOrder, location, temp;
for (firstOutOfOrder = 1; firstOutOfOrder < listLength; firstOutOfOrder++)
if (list[firstOutOfOrder] < list[firstOutOfOrder - 1]){
temp = list[firstOutOfOrder];
location = firstOutOfOrder;
do {
list[location] = list[location - 1];
location --;
} while (location > 0 && list[location - 1] > temp);
list[location] = temp;
}
}[/HIGHLIGHT]
Selection Sort
[HIGHLIGHT="Java5"]public static void selectSort (int[] list, int length){
int index, sIntex, minIndex, temp;
for (index = 0; index < length - 1; index ++){
sIndex = index;
for (minIndex = index + 1; minIndex < length; minIndex++)
if (list[minIndex] < list[sIndex])
sIndex = minIndex;
temp = list[sIndex];
list[sIndex] = list[index];
list[index] = temp;
}
}[/HIGHLIGHT]
This is the sequential search code i use
[HIGHLIGHT="Java5"]public static int seqSearch (int[] list, int length, int search){
int loc;
for (loc = 0; loc < length; loc++)
if (list[loc] == search)
return loc;
return -1;
}[/HIGHLIGHT]
Tease might also come in handy
bubble sort:
[HIGHLIGHT="Java5"]public static void bubbleSort (int[] list, int length){
int temp, counter, index;
for (counter = 0; counter < length - 1; counter ++){
for (index = 0; index < length - 1 - counter; index++)
if (list[index] > list[index + 1]){
temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
}
}
}[/HIGHLIGHT]
Insertion Sort
[HIGHLIGHT="Java5"]public static void insertionSort (int[] list, int listLength){
int firstOutOfOrder, location, temp;
for (firstOutOfOrder = 1; firstOutOfOrder < listLength; firstOutOfOrder++)
if (list[firstOutOfOrder] < list[firstOutOfOrder - 1]){
temp = list[firstOutOfOrder];
location = firstOutOfOrder;
do {
list[location] = list[location - 1];
location --;
} while (location > 0 && list[location - 1] > temp);
list[location] = temp;
}
}[/HIGHLIGHT]
Selection Sort
[HIGHLIGHT="Java5"]public static void selectSort (int[] list, int length){
int index, sIntex, minIndex, temp;
for (index = 0; index < length - 1; index ++){
sIndex = index;
for (minIndex = index + 1; minIndex < length; minIndex++)
if (list[minIndex] < list[sIndex])
sIndex = minIndex;
temp = list[sIndex];
list[sIndex] = list[index];
list[index] = temp;
}
}[/HIGHLIGHT]
~Aristotle said:
It is the mark of an educated mind to entertain a tought without accepting it
#3
Posted 22 January 2008 - 11:14 AM
From his attachment: Write a Java main method that calls the method.
Altough at first glance those methods will run, they are not recursive so i doubt he can turn that in.
That said, datastructures can be a pain if you dont know where to start. GL.
Altough at first glance those methods will run, they are not recursive so i doubt he can turn that in.
That said, datastructures can be a pain if you dont know where to start. GL.
#4
Posted 22 January 2008 - 12:23 PM
Turning those in would be cheating, eh?
~Aristotle said:
It is the mark of an educated mind to entertain a tought without accepting it
#5
Posted 22 January 2008 - 12:49 PM
gszauer said:
Turning those in would be cheating, eh?
Trust me, when students get desperate they just turn in whatever that looks like their assignments.
That said, hmm college.. a few more months before getting my uni cs degree. :D


Sign In
Create Account



Back to top









