public void LevelOrderTraversal() { if (_rootNode == null) { Console.WriteLine("Tree is empty!"); return; } var queue = new QueueLinkedList <NodeTree <TData> >(); queue.Enqueue(_rootNode); while (queue.Size() != 0) { var dequeuedElement = queue.Dequeue(); Console.WriteLine(dequeuedElement.Data); if (dequeuedElement.LeftChild != null) { queue.Enqueue(dequeuedElement.LeftChild); } if (dequeuedElement.RightChild != null) { queue.Enqueue(dequeuedElement.RightChild); } } Console.WriteLine(); }
/// <summary> /// This Method is used to test the DecksOfCardsUsingQueue Class. /// </summary> public static void DeckOfCardsUsingQueue() { try { Console.WriteLine(); Console.WriteLine("-----------------Deck of Cards Using Queue Program-----------------"); Console.WriteLine(); string[] suits = { "Clubs", "Diamonds", "Hearts", "Spades" }; string[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; QueueLinkedList player1 = new QueueLinkedList(); QueueLinkedList player2 = new QueueLinkedList(); QueueLinkedList player3 = new QueueLinkedList(); QueueLinkedList player4 = new QueueLinkedList(); player1 = Utility.DeckOfCard(suits, rank); player2 = Utility.DeckOfCard(suits, rank); player3 = Utility.DeckOfCard(suits, rank); player4 = Utility.DeckOfCard(suits, rank); while (player1.Size() != 0) { player1.Dequeue(); } Console.WriteLine(); while (player2.Size() != 0) { player2.Dequeue(); } Console.WriteLine(); while (player3.Size() != 0) { player3.Dequeue(); } Console.WriteLine(); while (player4.Size() != 0) { player4.Dequeue(); } Console.WriteLine(); } catch (Exception e) { Console.WriteLine("Message: {0}", e.Message); } }
public static void Main(string[] args) { QueueLinkedList <int> queue = new QueueLinkedList <int>(); Console.WriteLine($"Size(): {queue.Size()}"); Console.WriteLine($"IsEmpty(): {queue.IsEmpty()}"); Console.WriteLine(); queue.Enqueue(10); queue.Enqueue(20); queue.Enqueue(30); queue.Enqueue(40); Console.WriteLine($"Size(): {queue.Size()}"); Console.WriteLine($"IsEmpty(): {queue.IsEmpty()}"); Console.WriteLine(); Console.WriteLine($"Dequeue(): {queue.Dequeue().ToString()}"); Console.WriteLine($"Dequeue(): {queue.Dequeue().ToString()}"); Console.WriteLine(); Console.WriteLine($"Size(): {queue.Size()}"); // Expected Output: // ------------------ // Size(): 0 // IsEmpty(): True // // Enqueue(): 10 // Enqueue(): 20 // Enqueue(): 30 // Enqueue(): 40 // // Size(): 4 // IsEmpty(): False // // Dequeue(): 10 // Dequeue(): 20 // // Size(): 2 }
public void QueueSizeIncreases() { var queue = new QueueLinkedList <int>(); var size = 100; for (int i = 0; i < size; i++) { queue.Enqueue(i); } Assert.AreEqual(size, queue.Size()); }
public void Add_AddManyNumbersToQueueShouldWork(int count) { // Arrange QueueLinkedList <int> sut = new QueueLinkedList <int>(); int expected = count; // Act for (int i = 0; i < count; i++) { sut.Add(i); } int actual = sut.Size(); // Assert Assert.Equal(expected, actual); }
public void Clear_ClearQueueWithSomeNumbersShoulWork() { // Arrange QueueLinkedList <int> sut = new QueueLinkedList <int>(); int expected = 0; // Act sut.Add(int.MaxValue); sut.Add(int.MinValue); sut.Add(42); sut.Clear(); int actual = sut.Size(); // Assert Assert.Equal(expected, actual); }
public void StackSizeDecreases() { var queue = new QueueLinkedList <int>(); var size = 100; for (int i = 0; i < size; i++) { queue.Enqueue(i); } for (int i = 0; i < size; i++) { queue.Dequeue(); } Assert.AreEqual(0, queue.Size()); }
public void EmptyQueueSizeIsZero() { var queue = new QueueLinkedList <int>(); Assert.AreEqual(0, queue.Size()); }