I'm having trouble implementing a method to retrieve the information in a node given its location. For example, a location of 1 would return the head. A location of 2 would return the node just before the head.
if (location ==1)
return top();
else
for (int i =1; i < LinkedStack.size(); i++){
return LLNode.getInfo(location);
}
return null;
^Thats what I have but its completely wrong.
asked Aug 28, 2015 at 21:32
1 Answer 1
Just loop through the list so do something like:
current = top();
for (int i = 1; i < location ; i++){
current = current.next;
}
return current;
you may also want to add an if statement so if the location is larger than the list than return a message or something
answered Aug 28, 2015 at 21:36
lang-java