GeeCON Prague 2014*
The moose likes Java in General and the fly likes Need help with sorting random array of integers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help with sorting random array of integers" Watch "Need help with sorting random array of integers" New topic
Author

Need help with sorting random array of integers

Ray Chappel
Greenhorn

Joined: Feb 02, 2013
Posts: 10
I am not sure if this belongs here or in beginners. I have been working on this assignment for a while now and I can't figure this one issue out. I was given four files, Name.java, SortableArrayList.java, NameListDriver.java, and SortableArrayListWithBubbleSort.java. The program is meant to take a text file with a list of names and sort them alphabetically. Part one of the assignment was to change the bubble sort to a recursive selection sort. I seem to have completed that part. The second part requires me to make a driver that does the following things: Fill an array with random integers, output the array before sorting, then sort the array and output the sorted array. The size of the array is determined by a command line argument. It is supposed to be sorted by the same method that sorts the text file. I am able to create the array of random integers and output them, but I cant sort them.

Here is the randomDriver.java, which creates the array and outputs.



Now here is the SortableArrayListWithSelectionSortII.java that sorts the array. It works for the list of names, but not for the integers. It seems like the if (lowIndex < highIndex) statement isnt working for the array of integers.



Here is the SortableArrayList abstract class




It seems like the problem is with the first if statement in SortableArrayListWithSelectionSortII.java. It doesn't work with the bubble sort method that was originally supplied to me either. I am wondering if it might have to do with either variable names or data types? My sanity appreciates the help.

Please help me raise money to study abroad with Temple University in Tokyo, Japan. Please follow the link to donate. I appreciate any amount of money that you are willing to give. Any money donated will go ONLY towards tuition and program costs. Thank you again.
http://www.gofundme.com/22z71g
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2383
    
  28

It's difficult to wade through 350 lines of code. Have you tried debugging through the code? Can you make a SSCCE? It might help narrow down your problem
Ray Chappel
Greenhorn

Joined: Feb 02, 2013
Posts: 10
I took out the classes, methods, and files that I don't think pertain to my problem. I have tried debugging and have spent a lot of time on this and I have hit a brick wall and can not figure this out.
Ray Chappel
Greenhorn

Joined: Feb 02, 2013
Posts: 10


I was told this by someone else on another forum. It makes sense to me, but I'm just not sure how to fix the issue.

You create an empty SortableArrayList called nameList, then you print some stuff that's not connected to nameList, then you sort nameList even though it is empty, then you print some other stuff not connected to nameList. I expect that accomplishes very little.

I also notice that you print listItem twice without changing it between the two printings. That doesn't seem useful either.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2302
    
  49
I was told this by someone else on another forum. It makes sense to me, but I'm just not sure how to fix the issue.

Just looking at the extract of code shown (I don't have the time to wade through you initial post) and the attached comment I would say you have to copy the data from listItem to nameList and print out the contents of nameList.
Ray Chappel
Greenhorn

Joined: Feb 02, 2013
Posts: 10
thank you for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with sorting random array of integers