sorting - Creating a sorted Linked List in Java -



sorting - Creating a sorted Linked List in Java -

so supposed sort linked list in java alphabetical order (the nodes strings). not allowed utilize collections have create own linked list , sorting algorithm. have created method finds largest (or furthest downwards alphabet) word in linked list work. trying sort taking linked list, finding largest element , inserting new linked list. removes largest , goes doing same until linked list empty. ending blank list when run it, wrong code?

code returns largest element

public link islargest(){ link big = first; link temp = null; link current = first; link after = current.next; while (after != null){ if (large.lastname.compareto(after.lastname) < 0){ big = after; } temp = current; current = temp.next; after = current.next; } homecoming large; }

to remove, set largest element teh front end remove it.

private static linkedlist linksort(linkedlist unsorted){ linkedlist sorted = new linkedlist(); while (!(unsorted.isempty())){ link big = unsorted.islargest(); sorted.insert(large.name, large.lastname); first = large; unsorted.removefront(); } homecoming sorted; }

after find largest link, remove link @ head (removefront) of linkedlist. incorrect, because link @ head not largest link. need remove largest link.

java sorting linked-list

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -