I want to sort a vector contains like [a,b,1,3,5,z]
both ascending and descending on Java ME, i.e. without using function like Collections.sort()
views:
411answers:
4
A:
If it's a vector you can have a look at this example:
http://www.java-examples.com/sort-java-vector-descending-order-using-comparator-example
Cristian Boariu
2009-12-10 08:49:26
"With out using function like Collections.sort() ..."
Jesper
2009-12-10 09:00:51
A:
Copy the implementation of Collections.sort(), paste and modify it so much that you will be able to claim that you have "only been inspired" by it.
It's not cheating, it's learning from the chosen implementation.
Joel
2009-12-10 09:26:05
not so that you can cheat. but it is always a good exercise to go to the source code to find out how things are actually done.
Ron Tuffin
2009-12-10 09:30:57
If you are asked, for whatever reason, to re-invent the wheel, what would you do?Check how the wheel has been invented in the first place and do the same - good professionals do exactly that
Joel
2009-12-10 09:53:42
a) This is obviously a homework answer, not a "real world" question, telling them to copy the code is not helping them to learn. b) In the real world you might use it as a source of inspiration, but do you really want to expose yourself and your company to the legal nightmares of copyright infringement?
Paul Wagland
2009-12-10 10:19:36
I guess we'll never agree on that. Anyway nothing is more "real" for Michael than his homework. Chances are that he'll take my advise, and if so, he'll get a best practice how to solve a problem.
Joel
2009-12-10 10:45:35
Gareth Davis
2009-12-10 10:48:03
+1
A:
Exchange sort in 3 sentences:
- Find the smallest item in the vector, and exchange it with the first element in the vector.
- Sort the rest of the vector, i.e. pretend your vector starts at the next element after the first one (or whichever one you just did).
- If there's no more "rest of the vector" because you've just allocated the last position, you're done.
Carl Smotricz
2009-12-10 09:26:28