Hello,
it's me again... first thank u so much for ur help with my last java stuff... it went brilliant...
now my IT exam is in about 3 weeks and at the moment i am just revising... but the main problem is, that we get 40% of our marks through java... we have to write programms in our exam on paper... horrible...
but the good thing is, that there can be only a couple of programs be asked... only the ones which we did in my lectures :-)
but as we never got the code.. i thought about just writing some of the sorting programms so that i have some idea about it and that i am getting into it better... and they r actually quite similar :-)
so my first one which i did was quicksort... but it is not probable working... so i was wondering if anyone of u could have a short look on it and tell me what is wrong... that would be so lovely...
thank u so much
little_polarbear
oh and there is one stupid thing... i wanted to give out the sorted numbers, but it is not working... i know it is stupid... i should know by this time how to do it... but it just doesn't work :-(
import java.io.*;
public class quicksort
{
private int[] reading(String fileName)
throws FileNotFoundException
{
int[] array = null;
try
{
BufferedReader in = new BufferedReader(new FileReader(fileName));
String zeile = null;
int line = 0;
while(in.readLine() != null)
line++;
in.close();
array = new int[line];
in = new BufferedReader(new FileReader(fileName));
for(int v = 0; v<line; v++)
{
zeile = in.readLine();
array[v] = Integer.parseInt(zeile);
System.out.println(array[v]);
}
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return array;
}
public int [] quickSort(int[] array, int beginning, int end)
{
if (end> beginning){
int pivot = beginning;
int middle = beginning;
for (int i=beginning+1; i<= end; i++){
if (array[i]< array[middle]){
middle++;
swap(array, i, middle);
}
}
swap(array, pivot, middle);
array= quickSort(array, middle+1, end);
array =quickSort(array, beginning, middle-1);
System.out.println(array);
}
return array;
}
private void swap(int[] result, int a, int b){
int temp = result[a];
result[a] = result[b];
result[b] = temp;
}
public static void main(String[] args)
throws FileNotFoundException
{
quicksort app = new quicksort();
int[] array = app.reading("fielpath");
}
}