File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Having trouble with my Sorting Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Having trouble with my Sorting Program" Watch "Having trouble with my Sorting Program" New topic
Author

Having trouble with my Sorting Program

Hernan Delgado
Greenhorn

Joined: May 12, 2013
Posts: 1
I'm writing a Sorting program that prompts the user to enter a filename and then opens the file. It will read the comment from the first line and also read an integer N from the second line. It then reads N integers from the rest of the file and puts them into consecutive locations in an array. Once it does all this the program will then write the name of the input file and will sort an identical copy of the array using selection sort and merge sort(two classes that I have already. it finally writes a report of the number of compares and moves done in each sort and then asks the user if he wishes to continue.

My program as of right now asks the user for the text file and prints out whats inside. I'm having trouble with where i need it to write the name of the input file and will sort an identical copy of the array using selection sort and merge sort. I also am having trouble making it write the report of the number of compares and moves done in each sort.

This is what my program is supposed to look like when it outputs:

Enter Filename: ord50
File Name: ord50

File Comment: This is an ordered list of 50 numbers.

selection sort starting ... done
merge sort starting ... done
Here are the results of the sorts:

compares moves

selection sort 1225 147
merge sort 153 572

How can i go about making my program print like this?

Here's my code so far, i have three classes; driver class, mergesort class, and selection class.

Driver class:



MergeSort class:



Selection class:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble with my Sorting Program