public void LinkedListStackTest() { var stack = new LinkedListStack <int>(); stack.Push(1); stack.Push(2); Assert.IsTrue(stack.ItemCount == 2); Assert.IsTrue(stack.IsEmpty() == false); Assert.IsTrue(stack.Peek() == 2); Assert.IsTrue(stack.Pop() == 2); Assert.IsTrue(stack.ItemCount == 1); stack.Pop(); Assert.IsTrue(stack.IsEmpty()); for (int i = 0; i < 1000; i++) { stack.Push(i); } Assert.IsTrue(stack.ItemCount == 1000); for (int i = 0; i < 1000; i++) { stack.Pop(); } Assert.IsTrue(stack.ItemCount == 0); }
private string ShuntingYard(string input) { LinkedListStack <char> operators = new LinkedListStack <char>(); Queue <char> output = new LinkedListQueue <char>(); foreach (var i in input) { if (Char.IsNumber(i)) { output.Enqueue(i); } if (IsOperator(i)) { while (!operators.IsEmpty() && OperatorPrecedence(operators.Peek()) >= OperatorPrecedence(i)) { output.Enqueue(operators.Pop()); } operators.Push(i); } if (i == '(') { operators.Push(i); } if (i == ')') { while (operators.Peek() != '(') { output.Enqueue(operators.Pop()); } operators.Pop(); } } while (!operators.IsEmpty()) { output.Enqueue(operators.Pop()); } return(new string(output.ToArray())); }
static void Main(string[] args) { LinkedList list = new LinkedList(); LinkedListStack stack = new LinkedListStack(); LinkedListQueue queue = new LinkedListQueue(); list.Add(56); list.Add(70); list.Add(90); list.Add(12); list.Add(30); list.Add(60); list.AddInReverseOrder(22); list.AddInReverseOrder(44); list.InsertAtParticularPosition(2, 12); list.Display(); list.Total(); list.DeleteFirst(); list.DeleteLast(); list.SearchValueInList(90); stack.Push(10); stack.Push(20); stack.Push(30); stack.Push(40); stack.Push(50); stack.Display(); stack.Peek(); stack.Pop(); stack.IsEmpty(); queue.Enqueue(12); queue.Enqueue(24); queue.Enqueue(36); queue.Enqueue(48); queue.Dequeue(); queue.Display(); Console.ReadKey(); }