public void NonEmptyStackHasCorrectEmptyFlag() { var s = new StackViaLinkedList <int>(); s.Push(34); Assert.False(s.IsEmpty()); }
public static string InOrderTraversalReturnAsString(BinaryTreeNode <int> treeNode) { StringBuilder returnString = new StringBuilder(); StackViaLinkedList <BinaryTreeNode <int> > st = new StackViaLinkedList <BinaryTreeNode <int> >(); st.Push(treeNode); BinaryTreeNode <int> currentNode = treeNode; bool shouldCheckLeft = true; while (!st.IsEmpty()) { while (currentNode.Left != null && shouldCheckLeft) { st.Push(currentNode.Left); currentNode = currentNode.Left; } currentNode = st.Pop().Data; shouldCheckLeft = false; returnString.Append(currentNode.Data + " "); if (currentNode.Right != null) { st.Push(currentNode.Right); currentNode = currentNode.Right; shouldCheckLeft = true; } } return(returnString.ToString()); }
public static void InOrderTraversalIterative(BinarySearchTreeNode <int> treeNode) { StackViaLinkedList <BinarySearchTreeNode <int> > st = new StackViaLinkedList <BinarySearchTreeNode <int> >(); st.Push(treeNode); BinarySearchTreeNode <int> currentNode = treeNode; bool shouldCheckLeft = true; while (!st.IsEmpty()) { while (currentNode.Left != null && shouldCheckLeft) { st.Push(currentNode.Left); currentNode = currentNode.Left; } currentNode = st.Pop().Data; shouldCheckLeft = false; Console.Write(currentNode.Data + " "); if (currentNode.Right != null) { st.Push(currentNode.Right); currentNode = currentNode.Right; shouldCheckLeft = true; } } }
public void EmptyFlagIsCorectAfterStackBecomesEmpty() { var s = new StackViaLinkedList <int>(); s.Push(7); s.Pop(); Assert.True(s.IsEmpty()); }
public void NewStackHasCorrectEmptyFlag() { var s = new StackViaLinkedList <int>(); Assert.True(s.IsEmpty()); }