Link to home
Start Free TrialLog in
Avatar of cms_it_tlv
cms_it_tlv

asked on

Sorting a Linked List?

Here is the "driver" code:

public class L1014d {

      public static void main (String args[]) {
            // construct a view
            L1014v v = new L1014v();
            L1014m m = new L1014m(v);
            v.printList();            
      } // main method

}

Here is the "view" code:

public class L1014v {

   public L1014n br; // base address of list
   
   public void printList() {
           L1014n ln;
           ln = br; // sets local node to base;
           if (ln != null) {
              do {
                     System.out.println("Node is currently: " + ln.value);
                     ln = ln.nodeRef;
              } while (ln != null);
           } else {
                  System.out.println("No value in the node!");
           }
   }
   
   
   public void setRef(L1014n lr) {
           br = lr; // set base address of s1
   }

}

Here is the "model" code:

public class L1014m {

   L1014n baseRef;
   L1014n holdRef;
   L1014v viewRef;
   
   public L1014m(L1014v lf) {
           L1014n baseRef = new L1014n();
           L1014n holdRef = baseRef;
           L1014v viewRef = lf;
           for (int i = 0; i < 1000; i++) {
                  holdRef.nodeRef = new L1014n();
                  holdRef = holdRef.nodeRef;
           }
           lf.setRef(baseRef);
   }

}

and, here is the "node" code:

public class L1014n {

   L1014n nodeRef;
   int value = (int) (Math.random()*10000);

}

My question is, how do I get the linked-list and sort on the value in the L1014n class, but not by swapping the L1014n's value but just the L1014n nodeRef?

Help?
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did that help?

If so, you should grade the answer.

If not, perhaps a clarifying question would help.
Avatar of Mick Barry
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept imladris's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

objects
EE Cleanup Volunteer