// Behaviors public void Push(Type newObj) { LinkedStackNode <Type> newTop = new LinkedStackNode <Type>(newObj); newTop.SetNextNode(top); top = newTop; }
public Type Pop() { LinkedStackNode <Type> savedTop = top; top = savedTop.GetNextNode(); savedTop.SetNextNode(null); return(savedTop.GetHeldObj()); }
public void DisplayStack() { LinkedStackNode <Type> workingNode = top; Console.WriteLine("<LinkedStack>:"); while (workingNode != null) { Console.WriteLine(workingNode.ToString()); workingNode = workingNode.GetNextNode(); } }
public override string ToString() { string stackAsString = ""; LinkedStackNode <Type> workingNode = top; while (workingNode != null) { stackAsString += workingNode.ToString() + "\n"; workingNode = workingNode.GetNextNode(); } return(stackAsString); }
public LinkedStack(LinkedStack <Type> stackToCopy) // Copy { LinkedStackNode <Type> thisWorkingNode, thatWorkingNode = stackToCopy.GetTop(); SetTop(null); if (thatWorkingNode != null) { SetTop(new LinkedStackNode <Type>(thatWorkingNode)); thisWorkingNode = top; thatWorkingNode = thatWorkingNode.GetNextNode(); while (thatWorkingNode != null) { thisWorkingNode.SetNextNode(new LinkedStackNode <Type>(thatWorkingNode)); thisWorkingNode = thisWorkingNode.GetNextNode(); thatWorkingNode = thatWorkingNode.GetNextNode(); } } }
public void SetNextNode(LinkedStackNode <Type> inNextNode) { nextNode = inNextNode; }
public LinkedStackNode(LinkedStackNode <Type> nodeToCopy) // Copy { heldObj = nodeToCopy.GetHeldObj(); nextNode = null; }
public LinkedStackNode(Type inObj) // Initialize { heldObj = inObj; nextNode = null; }
// Constructors public LinkedStackNode() { nextNode = null; }
private void SetTop(LinkedStackNode <Type> inTop) { top = inTop; }
public LinkedStack(Type inObj) // Initialize { top = new LinkedStackNode <Type>(inObj); }
// Constructors public LinkedStack() // Default { top = null; }