You might want to take a look at java.util.Arrays.
posted 17 years ago
Thanks Rob but we are not allowed to use arrays. I just dont understand how to sort from the lowest value to the highest i.e... num1 = 5 num2 = 55 num3 = 9 num4 = 2 num5 = 72, so it should be like this 2, 5, 9, 55, 72
Hello, If you're just trying to learn the concepts of different sorting routines, then this is a decent place to begin (it does use arrays, but their use is not required, especially if you have just five numbers to sort): Chapter 4 of Handbook of Algorithms and Data Structures The Bubble Sort is a good starting point. The basic concept of the Bubble Sort is to go through the list one item at a time comparing it to each item and switch their order if the second one is smaller (or bigger if that's how you're using it). An excellent advanced sorting method is the Merge Sort. For more leads to understanding sorting concepts, go to the top-right of this page and click on search. I find this is often a good place to start with any of my questions, as many of these topics have been discussed at JavaRanch before. The use of Collections will enable you to sort many (if not all) things without having to code your own sorting methods. But, it won't teach you much about how sorting works and it can be a very slow option - depending on what you are sorting and how you want to sort it. Lastly, if you wanted to post your code, I (and I'm sure others) would be happy to review it and make suggestions. Good Luck, -Dirk Schreckmann