over 4 years ago
I want to write a recursive method which sorts the singly linked list and takes only one argument. And do not write another auxiliary method to support this recursive method.
about 4 years ago
I have a solution, not the fastest one, but it respect the conditions.
Imagine your list is :
this.integer = integer;
Then you can sort like this :
void sort(LinkedInt linkedInt)
if (linkedInt == null || linkedInt.next == null)
LinkedInt current = linkedInt;
while (current.next != null && current.integer > current.next.integer)
temp = current.integer;
current.integer = current.next.integer;
current.next.integer = temp;
current = current.next;
It sorts, it is recursive, it have only one parameter and not depends on other method.
The idea : we sort the queue first, then since queue is sorted, it is easy to push the value to the good place.
Hope it's Help
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2020 FindNerd.com. All rights reserved.
Sign up using