Results 1 to 2 of 2
Thread: Help with this linklist method
- 09-09-2010, 06:40 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 49
- Rep Power
- 0
Help with this linklist method
Java Code:public void add(int item){ if(head == null){ head = new Node(item); size++; }else{ //code goes here ??? HELP me with this,,please }
------------
LinkList x = new LinkList();
x.add(4);
x.add(5);
---------so i should have a list of 4,5 .........:confused::confused::confused:
- 09-10-2010, 12:49 AM #2
probably something like
Java Code:Node lastNode = null; Node currentNode = head; // walk thru the list of nodes until we get to the last node while (currentNode != null) { lastNode = currentNode; currentNode = currentNode.getNext(); } // while // now that we have the last node, append a new node to it. lastNode.setNext( new Node(item) );
Similar Threads
-
Help: Class LinkList, Method checkAges()
By Rhez in forum New To JavaReplies: 6Last Post: 04-20-2010, 05:29 AM -
Linklist
By buckey in forum New To JavaReplies: 3Last Post: 03-31-2010, 02:58 AM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 07:20 PM -
Sorted LinkList problem
By koolaqua16 in forum Advanced JavaReplies: 1Last Post: 08-08-2009, 06:49 AM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks