I want to sort a v开发者_运维问答ector contains like [a,b,1,3,5,z]
both ascending and descending on Java ME, i.e. without using function like Collections.sort()
Implement a sorting algorithm yourself then.
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.
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
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.
精彩评论