Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 1 Answer(s)

  • I have a solution, not the fastest one, but it respect the conditions. Imagine your list is :

    class LinkedInt
    {
        int integer;
        LinkedInt next;
    
        LinkedInt(int integer)
        {
            this.integer = integer;
        }
    }
    

    Then you can sort like this :

    void sort(LinkedInt linkedInt)
    {
         if (linkedInt == null || linkedInt.next == null)
            return;
    
         sort(linkedInt.next);
         LinkedInt current = linkedInt;
         int temp;
    
         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 JHelp

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: