public void ClearShouldRemoveAllOfTheDataInTheStack() { //Arrange var expectedResult = 0; //Act stack.Clear(); var actualResult = stack.Count; //Assert Assert.AreEqual(expectedResult, actualResult); }
private static void Main() { var studentStack = new CustomStack<Student>(); studentStack.Push(new Student("Pesho", 22)); studentStack.Push(new Student("Penka", 41)); studentStack.Push(new Student("Gosho", 7)); studentStack.Push(new Student("Kuci", 15)); Console.WriteLine(studentStack.Min().Name); var intStack = new CustomStack<int>(); intStack.Push(4); intStack.Push(5); intStack.Push(14); intStack.Push(42); intStack.Push(455); intStack.Pop(); intStack.Pop(); Console.WriteLine(intStack.Min()); intStack.Clear(); Console.WriteLine(intStack.Count); Console.WriteLine(intStack.IsEmpty); Console.WriteLine(intStack); }
public void TestClear_EmptyStack() { CustomStack <int> stack = new CustomStack <int>(); stack.Clear(); Assert.AreEqual(0, stack.Count); Assert.AreEqual(string.Empty, stack.ToString()); }
public void Clear_IsEmptyReturnsTrue(int[] numbers) { foreach (int number in numbers) { _stack.Push(number); } _stack.Clear(); Assert.That(_stack.IsEmpty, Is.True); }
static void Main(string[] args) { using (reader = File.OpenText("input.txt")) using (writer = new StreamWriter(File.Create("output.txt"))) { int n = reader.ReadInt(); CustomStack <char> stack = new CustomStack <char>(10001); while (n > 0) { stack.Clear(); string str = reader.ReadToken(); bool right = true; for (int i = 0; i < str.Length && right; i++) { switch (str[i]) { case '(': case '[': stack.Push(str[i]); break; case ')': if (stack.IsEmpty()) { right = false; } else { char c = stack.Pop(); right = (c == '('); } break; case ']': if (stack.IsEmpty()) { right = false; } else { char c = stack.Pop(); right = (c == '['); } break; } } right = right && stack.IsEmpty(); writer.WriteLine(right ? "YES" : "NO"); n--; } } }
public void TestClear_NonEmptyStack() { CustomStack <int> stack = new CustomStack <int>(); int stackCount = 5; for (int i = 0; i < stackCount; i++) { stack.Push(i); } stack.Clear(); Assert.AreEqual(0, stack.Count); Assert.AreEqual(string.Empty, stack.ToString()); }
public void Clear_CorrectWork() { CustomStack <int> stack = new CustomStack <int>(); stack.Push(1); stack.Push(2); stack.Clear(); try { stack.Pop(); Assert.Fail(); } catch (InvalidOperationException) { } }
public override void EnterProgram([NotNull] COOLParser.ProgramContext context) { base.EnterProgram(context); depthTables.Clear(); Log("enter Program"); if (phase == Phase.Building) { symbolTableCreator.EnterProgram(context); } else { depthTables.Push(rootSymbolTable); symbolTableCreator.CheckSymbolTablesErrors(); //travers symbol tables hierarchy and check errors symbolTableTraverser.EnterProgram(context); semanticErrorChecker.EnterProgram(context); } }
static void Main() { var stack = new CustomStack<int>(); var studentStack = new CustomStack<Student>(); studentStack.Push(new Student("Pesho", 12)); studentStack.Push(new Student("Gosho", 22)); studentStack.Push(new Student("Minka", 23)); studentStack.Push(new Student("Stamat", 45)); studentStack.Push(new Student("Kiril", 33)); Console.WriteLine(studentStack.Min().Name); stack.Push(4); stack.Push(3); stack.Push(44); stack.Push(31); stack.Push(12); stack.Push(8); stack.Pop(); stack.Pop(); Console.WriteLine(stack); Console.WriteLine(stack.Count); Console.WriteLine(stack.IsEmpty); Console.WriteLine(stack.Contains(4)); Console.WriteLine(stack.Contains(111)); Console.WriteLine(stack.Min()); stack.Clear(); Console.WriteLine(stack); Console.WriteLine(stack.Count); Console.WriteLine(stack.IsEmpty); }
static void Main() { try { // استک و صف همزمان Console.WriteLine("queue: "); FifoLifoList <string> fl = new FifoLifoList <string>((int)CollectionNames.Queue); fl.Add("a"); fl.Add("b"); fl.Add("c"); Console.WriteLine(fl.Remove().GetData()); Console.WriteLine(fl.Remove().GetData()); Console.WriteLine("stack: "); // استک و صف همزمان FifoLifoList <string> fl2 = new FifoLifoList <string>((int)CollectionNames.Stack); fl2.Add("a"); fl2.Add("b"); fl2.Add("c"); Console.WriteLine(fl2.Remove().GetData()); Console.WriteLine(fl2.Remove().GetData()); // (استک با پایه آرایه برای سرعت بیشتر (چون ولیو تایپ است Console.WriteLine("ArrayBasedStack: "); ArrayBasedStack <int> arbStack = new ArrayBasedStack <int>(); arbStack.Push(1); arbStack.Push(2); arbStack.Push(3); Console.WriteLine(arbStack.Pop()); Console.WriteLine(arbStack.Pop()); //--------------------------- Console.WriteLine("CustomQueue: "); CustomQueue <string> cq = new CustomQueue <string>(); cq.EnQueue("a"); cq.EnQueue("b"); cq.EnQueue("c"); Console.WriteLine(cq.DeQueue().GetData()); Console.WriteLine(cq.DeQueue().GetData()); cq.Clear(); //Console.WriteLine(cq.DeQueue().Data); Console.WriteLine("CustomStack: "); CustomStack <int> numbers = new CustomStack <int>(); numbers.Push(1); numbers.Push(2); numbers.Push(3); numbers.Push(4); numbers.Push(5); numbers.PrintAll(); Console.WriteLine("Count of stack is: {0}", numbers.Count()); Console.WriteLine("Popping {0}", numbers.PopData()); Console.WriteLine("Popping {0}", numbers.PopData()); numbers.Clear(); //Console.WriteLine("Popping '{0}'", numbers.Pop2()); //------------------- CustomStack <string> stack = new CustomStack <string>(); stack.Push("first"); stack.Push("second"); stack.Push("third"); Console.WriteLine("\nall data"); stack.PrintAll(); Console.WriteLine("\nPeek"); Console.WriteLine(stack.PeekFromStack().GetData()); Console.WriteLine("\nPrintAll again"); stack.PrintAll(); Console.WriteLine("\nnow try to pop"); Console.WriteLine(stack.Pop().GetData()); Console.WriteLine("\nPrintAll again"); stack.PrintAll(); Console.WriteLine("\nnow try to popping two items "); Console.WriteLine("Popping {0}", stack.Pop().GetData()); Console.WriteLine("Popping {0}", stack.Pop().GetData()); Console.WriteLine("\nPrintAll again"); stack.PrintAll(); Console.WriteLine("\nPush three item"); stack.Push("first"); stack.Push("second"); stack.Push("third"); stack.PrintAll(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void Stack_Clear_Test() { stack.Clear(); Assert.IsTrue(stack.Count == 0); }