Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with sorting random array of integers

 
Ray Chappel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic