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); }
static void Main(string[] args) { var operatingUnitName = "陳俊欽-紅不讓手機配件-鳳山店"; var index = operatingUnitName.IndexOf("-") + 1; var storeName = operatingUnitName.Substring(index, operatingUnitName.Length - index); var v1 = 0 / 2; var v2 = 1 / 2; var v3 = 2 / 2; var aa = new List <string>() { "a", "b", "c", "d", "e", "f", "g" }; var a = aa.Select((item, inx) => new { item, inx }) .GroupBy(x => x.inx / 2); var myStackQueue = new StackQueue <int>(); //T is now int myStackQueue.Enqueue(1); myStackQueue.Push(2); myStackQueue.Push(3); myStackQueue.Enqueue(4); //At this point, the collection is { 3, 2, 1, 4 } foreach (var item in myStackQueue) { Console.WriteLine(item); } }
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 StackQueueAddedItemCountTest() { StackQueue sq = new StackQueue(); sq.Enqueue(new StackQueueElement() { ElementValue = 1 }); sq.Enqueue(new StackQueueElement() { ElementValue = 2 }); sq.Enqueue(new StackQueueElement() { ElementValue = 3 }); Assert.AreEqual(3, sq.Count()); }
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++; } }