public Type Pop() { LinkedStackNode <Type> savedTop = top; top = savedTop.GetNextNode(); savedTop.SetNextNode(null); return(savedTop.GetHeldObj()); }
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 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); }