Class LLNode

java.lang.Object
  extended by LLNode
Direct Known Subclasses:
AgentNode, CharacterNode

public abstract class LLNode
extends Object

Class that represents a node in a linked list

Author:
Mark Guzdial, Barb Ericson

Constructor Summary
LLNode()
          Constructor for LLNode that just sets next to null
 
Method Summary
 void add(LLNode node)
          Add the passed node after the last node in this list.
 int count()
          Return the number of the elements in the list
 LLNode getNext()
          Method to get the next element
 void insertAfter(LLNode node)
          Insert the input node after this node.
 LLNode last()
          Return the last element in the list
 void remove(LLNode node)
          Method to remove a node from the list, fixing the next links appropriately.
 LLNode reverse()
          Reverse the list starting at this, and return the last element of the list.
 LLNode reverse2()
          Reverse2: Push all the elements on the stack, then pop all the elements off the stack.
 void setNext(LLNode nextOne)
          Method to set the next element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LLNode

public LLNode()
Constructor for LLNode that just sets next to null

Method Detail

setNext

public void setNext(LLNode nextOne)
Method to set the next element

Parameters:
nextOne - the element to set as next

getNext

public LLNode getNext()
Method to get the next element

Returns:
the next element in the linked list

remove

public void remove(LLNode node)
Method to remove a node from the list, fixing the next links appropriately.

Parameters:
node - the element to remove from the list.

insertAfter

public void insertAfter(LLNode node)
Insert the input node after this node.

Parameters:
node - element to insert after this.

last

public LLNode last()
Return the last element in the list

Returns:
the last element in the list

count

public int count()
Return the number of the elements in the list

Returns:
the number of elements in the list

add

public void add(LLNode node)
Add the passed node after the last node in this list.

Parameters:
node - the element to insert after this.

reverse

public LLNode reverse()
Reverse the list starting at this, and return the last element of the list. The last element becomes the FIRST element of the list, and THIS goes to null.

Returns:
the new head of the list

reverse2

public LLNode reverse2()
Reverse2: Push all the elements on the stack, then pop all the elements off the stack.

Returns:
the new head of the list