HALEN666 Posted April 1, 2010 Share Posted April 1, 2010 How would you sort in ascending order an arraylist in java. In other words. You have an arraylist (list1) nwith random values, how would you put those values in ascending order in a second arraylist(list2)? I have all the code, but I can get that part working, it is a logic error. Help please Quote Link to comment Share on other sites More sharing options...
Sparda Posted April 1, 2010 Share Posted April 1, 2010 There are a number of well known sorting algorithms that have been developed by mathematicians and software developers (or computer scientists if you want to have an impressive title). Pick one, they all work, some work better that others for different things. Quote Link to comment Share on other sites More sharing options...
HALEN666 Posted April 1, 2010 Author Share Posted April 1, 2010 I forgot to mentiones. I am not allowed to use any sorting method, such as sort, bubble sort, binary sort, etc. I pretty much have to compare each element in the array and put it in their correct place. I have spend 2 hours trying to figure it out and still can't get it to work. Quote Link to comment Share on other sites More sharing options...
requiem Posted April 1, 2010 Share Posted April 1, 2010 So you're not allowed to use a sorting algorithm, yet you have to sort? Are you sure it's just that you can't use predefined algorithms? Quote Link to comment Share on other sites More sharing options...
Sparda Posted April 1, 2010 Share Posted April 1, 2010 You could use the sort method from java.util.Collections, but that still uses a sorting algorithm. Quote Link to comment Share on other sites More sharing options...
Resix Posted April 2, 2010 Share Posted April 2, 2010 Hi! I just took a course in Java programming at University, and at the same time we discussed the sorting algorithms in Math, Big O, Small O and so on, for all Mathematicians out there. ;) I think your assignment is to Write a sorting algorithm without using already implemented functions. I'd say, try to program one of the easier sorting algorithms, you can find tutorials on them out there as well. I'd recommend looking at wikipedia, they usually have pseudocode aswell. Hmmm if you need help programming the stuff, just send me a pm or write it in here. I'm glad to help ;) PS: Sorting is always an algorithm of some sort to be precise. Quote Link to comment Share on other sites More sharing options...
StarchyPizza Posted April 5, 2010 Share Posted April 5, 2010 Yeah what you're looking to do is VERY similar to bubblesort and other sorting algorithms, and is probably the better way to do it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.