



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















c a e d b
firstNode
Normal Way To Draw A Linked List
link or pointer field of node
data field of node
a b c d e
null
firstNode
package dataStructures;
class ChainNode
{
// package visible data members Object element; ChainNode next;
// constructors come here
}
next element
ChainNode() {}
null null
null element
next element
ChainNode(Object element)
{this.element = element;}
ChainNode(Object element, ChainNode next)
{this.element = element; this.next = next;}
get(1)
checkIndex(1);
desiredNode = firstNode.next; // gets you to second node
return desiredNode.element;
a b c d e
null
firstNode
get(2)
checkIndex(2);
desiredNode = firstNode.next.next; // gets you to third node
return desiredNode.element;
a b c d e
null
firstNode
NullPointerException
desiredNode = firstNode.next.next.next.next.next.next; // gets the computer mad // you get a NullPointerException
a b c d e
null
firstNode
Remove An Element
remove(0)
a b c d e
null
firstNode
firstNode = firstNode.next;