Java quick sort, reading from a user input file into any array (to be sorted)

5 pts.
Tags:
Java
Java Array
Hey, What's up y'all,

I am trying to write some code in Java that will read in the numbers from a file (one # on each line of .txt file) put them into an array, and then run quick sort on the array. Eclipse is showing some red that I am having trouble with. My errors are marked with comments, and what the error is, if anyone can help me get this to run, thanks everyone!

-Kyle

[code]import java.io.*;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.File;


public class Lab3 {

public static void main(String[] args) throws IOException{


System.out.print("Name of file with array: ");
Scanner readIn = new Scanner(System.in);
String input=readIn.nextLine();}
**testScan1(input);**  /*Eclipse says "return type for method is missing" trying to call method testScan below*/


**public testScan1(String filename)**  //"Return type is missing for method"

{
File file = new File(filename);
Scanner scan;
try{
 int [] array = new int[5];

scan = new Scanner( file );
}
catch ( java.io.FileNotFoundException e )
{
System.out.println( "couldn't open. file not found "  );
return;
}
while(file.hasNext())      //"underlies "hasNext" "Method hasNext() is undefined"
{
for( int i = 0; i <= file.length(); ++i)
{

**array**[i]=scan.next();    //"Array cannot be Resolved"


}
}

int partition(int arr[], int left, int right)
{
 int i=left; int j = right;
 int tmp;
 int pivot = arr[(left+right)/2];
 while (i<=j){
  while(arr[i]<pivot)
   i++;
  while (arr[j]>pivot)
   j--;
  if (i<=j){
   tmp=arr[i];
   arr[i]=arr[j];
   arr[j]=tmp;
   i++; j--;
  }
 }
 return i;
    }
    void quickSort(int arr[], int left, int right){
 int index = partition(arr, left, right);
 if (left<index-1);
 quickSort(arr, left, index-1);
 if (index<right)
  quickSort(arr, index, right);
    }
    }
[/code][/pre]

Software/Hardware used:
Eclipse, java
ASKED: November 5, 2009  11:00 PM
UPDATED: November 10, 2009  11:18 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Instead of using .hasNext, using some sort of delimiter is what I’d suggest.

I’d also check into any .next methods, which are less prone to erroring out.

Hope this helps!

-Schmidtw

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following