Results 1 to 3 of 3
  1. #1
    Lindan_newjava is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Question basic linked list questions

    Java Code:
    public class Node  
      {  
           int value;  
           Node next;  
        
           Node(int value, Node next)  
          {  
              this.value = value;  
              this.next = next;  
           }  
        
           Node(int value)  
           {  
              this.value = value;  
           }  
      }  
          class TestNode   
          {  
        
          Node start;  
        
         void method inverse()  //I am confused...:confused:
          {  
             Node p = null;  
             Node q = start;
             for (; q != null; q = q.next)  
             {  
                 p = new Node(q.value,p);  
            }  
            start = p;  
          }
    .
    Question: 1.What does method inverse() do to a general linked list? 2.For a list with n items, what is the maximum number of items that are live during the method inverse()? 3.Give a simple modification of the method inverse() that minimizes the number of live items that necessary for the method to work.

    I am new to java, and I am having trouble with the linked list questions above. I see that after calling inverse(), the original list would be in inverse order, like change {1,2,3,4} to {4,3,2,1}. That is to say, we would create a new list, which containing same node values but in inverse order. I am wondering if I follow the question right.
    Assume the number of original list items is n. If I follow the first question right, the maximum items that living during the method inverse() would be the n, right? But how to minimizes the number of live items?:confused::confused::confused:

    Any tips or suggestions would be greatly appreciated.
    Last edited by DarrylBurke; 05-27-2011 at 12:05 PM. Reason: Added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default

    What is a "live" item?
    Are there other types of items: dead, asleep, moving, ???

  3. #3
    Lindan_newjava is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 9
    Last Post: 11-04-2011, 03:09 AM
  2. Replies: 4
    Last Post: 02-21-2011, 09:34 AM
  3. Basic GUI questions
    By sunde887 in forum New To Java
    Replies: 6
    Last Post: 02-11-2011, 06:11 PM
  4. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  5. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •