public static void DisplayListQueue() { ListBasedQueue <int> basedQueue = new ListBasedQueue <int>(); for (int i = 1; i <= 5; i++) { basedQueue.Enqueue(i); } while (!basedQueue.IsEmpty()) { Console.Write(basedQueue.Dequeue() + " "); } }
public static void ClearWorksCorrectly() { // Arrange var q = new ListBasedQueue <int>(); q.Enqueue(1); q.Enqueue(2); // Act q.Clear(); // Assert Assert.IsTrue(q.IsEmpty(), "Queue is empty"); Assert.IsFalse(q.IsFull(), "Queue is full"); }
public static void DisplayHamburgerSimulation() { ListBasedQueue <Hamburger> simulationQueue = new ListBasedQueue <Hamburger>(); Hamburger cheese = new Hamburger("cheese", 12); Hamburger hotBeef = new Hamburger("hotBeef", 15); Hamburger doubleB = new Hamburger("doubleB", 24); int orderTerm = 15; int procedureStatus = 0; for (int second = 0; second < 3600; second++) { if (second % orderTerm == 0) { Random random = new Random(); switch (random.Next(1, 4)) { case 1: simulationQueue.Enqueue(cheese); cheese.Count++; break; case 2: simulationQueue.Enqueue(hotBeef); hotBeef.Count++; break; case 3: simulationQueue.Enqueue(doubleB); doubleB.Count++; break; } } if (procedureStatus <= 0 && simulationQueue.IsEmpty()) { procedureStatus = simulationQueue.Dequeue().Term; } procedureStatus--; } Console.WriteLine("Simulation Report"); Console.WriteLine("Cheese : " + cheese.Count); Console.WriteLine("Bulgogi : " + hotBeef.Count); Console.WriteLine("Double : " + doubleB.Count); }
public static void PeekWorksCorrectly() { // Arrange var q = new ListBasedQueue <int>(); q.Enqueue(1); q.Enqueue(2); int peeked = 0; // Act for (int i = 0; i < 3; i++) { peeked = q.Peek(); } // Assert Assert.AreEqual(expected: 1, actual: peeked); Assert.IsFalse(q.IsEmpty(), "Queue is empty"); Assert.IsFalse(q.IsFull(), "Queue is full"); }
public void ShowVertexGraphWithBreadth(GraphVertex vertexStart) { Console.Write(vertexStart + "부터 탐색 : "); GraphVertex vertexVisit = vertexStart; VisitVertex(vertexVisit); ListBasedQueue <GraphVertex> queue = new ListBasedQueue <GraphVertex>(); while (_lists[(int)vertexVisit].ReadFirst()) { GraphVertex vertexNext = _lists[(int)vertexVisit].CurrentNode.Data; if (VisitVertex(vertexNext)) { queue.Enqueue(vertexNext); } while (_lists[(int)vertexVisit].ReadNext()) { vertexNext = _lists[(int)vertexVisit].CurrentNode.Data; if (VisitVertex(vertexNext)) { queue.Enqueue(vertexNext); } } if (queue.IsEmpty()) { break; } vertexVisit = queue.Dequeue(); } Console.WriteLine(); InitializeVisitInformation(); }
public static void DequeueWorksCorrectly() { // Arrange var q = new ListBasedQueue <char>(); q.Enqueue('A'); q.Enqueue('B'); q.Enqueue('C'); var result = new StringBuilder(); // Act for (int i = 0; i < 3; i++) { result.Append(q.Dequeue()); } // Assert Assert.AreEqual(expected: "ABC", actual: result.ToString()); Assert.IsTrue(q.IsEmpty(), "Queue is empty"); Assert.IsFalse(q.IsFull(), "Queue is full"); }