Manually sorting a linked list in Java (lexically) -


I am implementing my linked list in Java. There is only one string field in the node class called "name" And is a node called "link". Right now I have a test driver class which involves only several names in sequential order. Now, I am trying to type a sorting method to sort nodes according to the characters, but there is a problem with it. I From the post of someone else, I found this bubblest pseudo-stroke and tried to apply it, but it does not completely sort the entries. Is very sure that I do not appreciate any suggestions!

  Private zero type () Enter the // {Enter} loop only if there are elements in the boolean list = (head! = Null); // If swap is done {swapped = false; // monitor pointer node curr = head; Node next = curr.link; Node pre = null; // The last object can not be swapped with next time (next! = Null) {// swap if there are items in the wrong order (curr.name.compareTo (next.name))  

I spent a few minutes for errors on your code but no one found .

I say that unless someone has to work smarter or more difficult, then you should try Debugi If you have Eclipse like IDE on your own, you can do single-phase through the code, looking at the values ​​of the variable; If not, you can insert print statements in some places and check the hand You can do what you expect.


UPDATE I

I copied your code and tested it. In descending order (which may not be your intention), this is 0, 1 and 10 Drichchik fully working samples of nodes. So where's the problem?

UPDATE II

Still, what could be guessed "These entries do not sort completely." It is possible that you are expecting lexicographic sorting (i.e. 'B' before), and it is not planned for the words of mixed upper / lower case. In this case, resolve string method compare engineer (string str) .


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -