Results 1 to 3 of 3
Thread: linkedlist question
- 05-06-2012, 03:36 AM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
linkedlist question
class ChainNode { Object element; // an element of the list ChainNode next; // the next node in the chain
... // constructors (do not give codes!)
} public class Chain implements LinearList {
}
protected ChainNode firstNode; // the first node in the chain protected int size; // number of nodes in the chain
public Chain() {} // constructor
public Object get (int index) { // returns the element at the specified index in this list; // (the first element in the list has index 0)
... // YOUR CODE REPLACES DOTS HERE (subquestion 3.a)
}
I'm not too sure on what to do for the get() method, could someone tell me if this is the correct way going about it.
First get rid of the invalidindex exception.
chainNode cursor = firstelem;
for (int i=1 ; i <=index; i++){
cursor = cursor.getNext();}
return cursor;
- 05-06-2012, 04:31 AM #2
Member
- Join Date
- May 2012
- Posts
- 14
- Rep Power
- 0
- 05-06-2012, 04:37 AM #3
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
Similar Threads
-
Question about LinkedList Iterator
By kraigballa in forum New To JavaReplies: 7Last Post: 02-10-2012, 05:10 PM -
Java newbie question on linkedlist index search
By Mjall in forum New To JavaReplies: 5Last Post: 03-25-2011, 10:54 PM -
I need help in LinkedList ...
By Usman in forum Advanced JavaReplies: 3Last Post: 03-25-2011, 01:38 AM -
Quick LinkedList question
By mac in forum New To JavaReplies: 7Last Post: 05-31-2010, 01:27 AM -
LinkedList help
By jigglywiggly in forum New To JavaReplies: 6Last Post: 09-19-2009, 07:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks