public void Stack_And_Queue() { var sq = new StackQueue <int>(); for (var i = 0; i < 5; i++) { if (i % 2 == 0) { sq.Push(i); } else { sq.Enqueue(i); } } // 4 (push) // 3 (enqueue) // 2 (push) // 1 (enqueue) // 0 (push) Assert.AreEqual(4, sq.Pop()); Assert.AreEqual(0, sq.Dequeue()); Assert.AreEqual(3, sq.Pop()); Assert.AreEqual(1, sq.Dequeue()); Assert.AreEqual(2, sq.Pop()); }
public void StackQueueDequeuTest() { StackQueue sq = new StackQueue(); sq.Enqueue(new StackQueueElement() { ElementValue = 1 }); sq.Enqueue(new StackQueueElement() { ElementValue = 2 }); sq.Enqueue(new StackQueueElement() { ElementValue = 3 }); StackQueueElement ele = sq.Dequeue(); Assert.AreEqual(1, ele.ElementValue); StackQueueElement ele2 = sq.Dequeue(); Assert.AreEqual(2, ele2.ElementValue); }
private static void PerformQueueOps() { // Queue using array var arrayQueue = new ArrayQueue <int>(5); arrayQueue.Enqueue(10); arrayQueue.Enqueue(20); arrayQueue.Enqueue(30); Console.WriteLine(arrayQueue.Dequeue()); Console.WriteLine(arrayQueue.Dequeue()); arrayQueue.Enqueue(40); arrayQueue.Enqueue(50); arrayQueue.Enqueue(60); arrayQueue.Enqueue(70); // Queue using stack Console.WriteLine(arrayQueue.ToString()); var stackQueue = new StackQueue <int>(); stackQueue.Enqueue(10); stackQueue.Enqueue(20); stackQueue.Enqueue(30); Console.WriteLine(stackQueue.Dequeue()); Console.WriteLine(stackQueue.Dequeue()); Console.ReadLine(); //Priority Queue var priorityQueue = new PriorityQueue(5); priorityQueue.Enqueue(10); priorityQueue.Enqueue(8); priorityQueue.Enqueue(9); priorityQueue.Enqueue(7); Console.WriteLine(priorityQueue.ToString()); Console.ReadLine(); }
//SOL private static void solve(int[] arr, InOut.Ergebnis erg) { StackQueue <int> q = new StackQueue <int>(); string s = ""; foreach (int i in arr) { if (i != -1) { q.Enqueue(i); } else { s += " " + q.Dequeue(); } } erg.Setze(s.Trim(' ')); }
public void Queue() { var sq = new StackQueue <int>(); for (var i = 0; i < 3; i++) { sq.Enqueue(i); } var expected = 0; while (sq.Count > 0) { var next = sq.Dequeue(); Assert.AreEqual(expected, next); expected++; } }