Results 1 to 3 of 3
Thread: basic linked list questions
- 05-27-2011, 11:54 AM #1
Newbies
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
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
- 05-27-2011, 02:28 PM #2
What is a "live" item?
Are there other types of items: dead, asleep, moving, ???
- 05-27-2011, 02:41 PM #3
Newbies
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Basic Circular Linked List - addFirst() method works improperly
By carlodelmundo in forum New To JavaReplies: 9Last Post: 11-04-2011, 03:09 AM -
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
Basic GUI questions
By sunde887 in forum New To JavaReplies: 6Last Post: 02-11-2011, 06:11 PM -
Linked list inside a linked list
By viperlasson in forum New To JavaReplies: 5Last Post: 07-26-2010, 11:15 PM -
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks