static void Main(string[] args) { var arrayQueue = new ArrayQueue <string>(); arrayQueue.Enqueue("1"); arrayQueue.Enqueue("2"); arrayQueue.Enqueue("3"); arrayQueue.Enqueue("4"); arrayQueue.Enqueue("5"); arrayQueue.Dequeue(); arrayQueue.Dequeue(); arrayQueue.Dequeue(); arrayQueue.Dequeue(); var linkedListQueue = new LinkedListQueue <string>(); linkedListQueue.Enqueue("1"); linkedListQueue.Enqueue("2"); linkedListQueue.Enqueue("3"); linkedListQueue.Enqueue("4"); linkedListQueue.Enqueue("5"); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); }
public void TestLinkedListQueuePeek() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); // check that after peek we have the correct value but the item // is not deleted Assert.AreEqual(1, queue.Peek()); Assert.AreEqual(5, queue.Count); queue.Dequeue(); Assert.AreEqual(2, queue.Peek()); Assert.AreEqual(4, queue.Count); queue.Dequeue(); Assert.AreEqual(3, queue.Peek()); Assert.AreEqual(3, queue.Count); queue.Dequeue(); Assert.AreEqual(4, queue.Peek()); Assert.AreEqual(2, queue.Count); queue.Dequeue(); Assert.AreEqual(5, queue.Peek()); Assert.AreEqual(1, queue.Count); queue.Dequeue(); }
public Dog TakeDog() { if (_dogs.IsEmpty) { throw new Exception("No more dogs."); } return(_dogs.Dequeue().Item1); }
public Cat TakeCat() { if (_cats.IsEmpty) { throw new Exception("No more cats."); } return(_cats.Dequeue().Item1); }
public void QueueIsEnptyWhenAllElementsAreRemoved() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); Assert.Equal(1, sut.Dequeue()); Assert.Equal(2, sut.Dequeue()); Assert.True(sut.IsEmpty); }
public void Dequeue_Subtracts_To_Count() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Dequeue(); queue.Dequeue(); Assert.Equal(1, queue.Count); }
public void CircularQueueRemovesOldElementsToEnqueueNewOnes1() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); Assert.Equal(1, sut.Dequeue()); Assert.Equal(2, sut.Dequeue()); sut.Enqueue(4); Assert.Equal(4, sut.Dequeue()); Assert.True(sut.IsEmpty); }
public void QueueTest() { var q = new LinkedListQueue <int>(); q.Enqueue(1); q.Enqueue(2); Assert.IsTrue(q.Count == 2); int i = q.Dequeue(); Assert.IsTrue(i == 1); Assert.IsTrue(q.Count == 1); i = q.Dequeue(); Assert.IsTrue(i == 2); Assert.IsTrue(q.Count == 0); }
public void QueueWorksInFifoOrderWhenIntermittentEnqueuesAccure() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); sut.Enqueue(3); Assert.Equal(1, sut.Dequeue()); sut.Enqueue(4); sut.Enqueue(5); Assert.Equal(2, sut.Dequeue()); Assert.Equal(3, sut.Dequeue()); Assert.Equal(4, sut.Dequeue()); Assert.Equal(5, sut.Dequeue()); }
public void TestLinkedListQueuePeek() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); // check that after peek we have the correct value but the item // is not deleted Assert.AreEqual(1, queue.Peek()); Assert.AreEqual(5, queue.Count); queue.Dequeue(); Assert.AreEqual(2, queue.Peek()); Assert.AreEqual(4, queue.Count); queue.Dequeue(); Assert.AreEqual(3, queue.Peek()); Assert.AreEqual(3, queue.Count); queue.Dequeue(); Assert.AreEqual(4, queue.Peek()); Assert.AreEqual(2, queue.Count); queue.Dequeue(); Assert.AreEqual(5, queue.Peek()); Assert.AreEqual(1, queue.Count); queue.Dequeue(); }
public void DequeueOnEmptyQueueThrowsQueueEmptyExceptionTest() { LinkedListQueue target = new LinkedListQueue(); // TODO: Initialize to an appropriate value target.Dequeue(); Assert.Fail("Dequeued from empty queue didn't throw QueueEmptyException"); }
public static void TestLinkedListQueue() { LinkedListQueue <int> linkedListQueue = new LinkedListQueue <int>(); linkedListQueue.Enqueue(3); linkedListQueue.Enqueue(4); linkedListQueue.Enqueue(5); linkedListQueue.Enqueue(6); linkedListQueue.Enqueue(7); linkedListQueue.Enqueue(8); linkedListQueue.PrintItems(); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); linkedListQueue.PrintItems(); Console.ReadLine(); }
public void AddFiveItemsAndVerify() { int linkedListQueueLast = 0; int arrayQueueLast = 0; for (int i = 1; i <= 5; i++) { linkedListQueue.Enqueue(i); arrayQueue.Enqueue(i); } Assert.AreEqual(linkedListQueue.Peek(), 1, "invalid top element"); Assert.AreEqual(linkedListQueue.Count, 5, "invalid count"); Assert.AreEqual(arrayQueue.Peek(), 1, "invalid top element"); Assert.AreEqual(arrayQueue.Count, 5, "invalid count"); while (linkedListQueue.Count > 0) { linkedListQueueLast = linkedListQueue.Dequeue(); arrayQueueLast = arrayQueue.Dequeue(); } Assert.AreEqual(linkedListQueueLast, 5, "invalid last element"); Assert.AreEqual(arrayQueueLast, 5, "invalid last element"); }
public void Enqueue_And_Dequeue_Multiple_Items() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); var item = queue.Peek(); Assert.Equal(5, item); }
public void LinkedListDeqeueEnqueueTest() { for (var i = 0; i < Elements - 1; i++) { _linkedListQueue.Dequeue(); } Assert.AreEqual(1000000000, _linkedListQueue.Peek()); }
public void LinkedListQueue() { var queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(true, queue.IsEmpty()); }
public void SimpleTest() { var queue = new LinkedListQueue(); Assert.True(queue.IsEmpty); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); Assert.Equal(1, queue.Front); Assert.Equal(4, queue.Rear); Assert.Equal(1, queue.Dequeue()); Assert.Equal(2, queue.Dequeue()); Assert.Equal(3, queue.Dequeue()); Assert.Equal(4, queue.Dequeue()); }
public void TestLinkedListQueuePeek_ThrowsException() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Peek(); }
public void TestLinkedListQueueDequeue() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(4, queue.Count); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Count); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(1, queue.Count); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(0, queue.Count); }
public void TestLinkedListQueueDequeue() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(4, queue.Count); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Count); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(1, queue.Count); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(0, queue.Count); }
public void QueueStackWorksInFifoOrder() { var sut = new LinkedListQueue <int>(); for (var i = 0; i < 100; i++) { sut.Enqueue(i); } for (var i = 0; i < 100; i++) { Assert.Equal(i, sut.Dequeue()); } }
public void Enqueue_ExpectedTrue() { _queue.Enqueue("wo"); Assert.AreEqual(_queue.Count(), 1); _queue.Dequeue(); Assert.AreEqual(_queue.Count(), 0); var sb = new StringBuilder(); _queue.Enqueue("ni"); _queue.Enqueue("he"); _queue.Enqueue("wo"); _queue.Enqueue("shi"); _queue.Dequeue(); _queue.Enqueue("tian"); _queue.Dequeue(); _queue.Enqueue("cai"); foreach (var s in _queue) { sb.Append(s); } Assert.AreEqual("woshitiancai", sb.ToString()); Assert.AreEqual(_queue.Count(), 4); }
public void TestLinkedListQueue() { var queue = new LinkedListQueue <int>(); for (var i = 0; i < 10; i++) { queue.Enqueue(i); Console.WriteLine(queue); if (i % 3 == 2) { queue.Dequeue(); Console.WriteLine(queue); } } }
/// <summary> /// 任务下发逻辑 /// </summary> private static void IssueTasks() { lock (lockObject) { var now = DateTime.Now; RetryQueue.RemoveAll(room => { if (room.RetryAfter < now) { var client = ConnectedClient.FirstOrDefault(x => x.MaxParallelTask > x.CurrentJobs.Count && !room.Clients.Contains(x.Name)); if (client == default(CrawlerClient)) { client = ConnectedClient.FirstOrDefault(x => x.MaxParallelTask > x.CurrentJobs.Count); } if (client == default(CrawlerClient)) { return(false); } ConnectedClient.Remove(client); ConnectedClient.Add(client); SendTask(client, room); return(true); } else { return(false); } }); while (RoomQueue.Count > 0) { var client = ConnectedClient.FirstOrDefault(x => x.MaxParallelTask > x.CurrentJobs.Count); if (client == null) { return; } else { var room = RoomQueue.Dequeue(); ConnectedClient.Remove(client); ConnectedClient.Add(client); SendTask(client, room); } } } }
public void DataOrderPreservedTest() { LinkedListQueue target = new LinkedListQueue(); // TODO: Initialize to an appropriate value object[] testData = new object[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; for (int j = 0; j < 10; j++) { foreach (var x in testData) { target.Enqueue(x); } foreach (var x in testData) { Assert.AreEqual <object>(x, target.Dequeue(), "LinkedListQueue dequeueing elements in different order than they're enqueued in"); } Assert.AreEqual <int>(0, target.Count, "LinkedListQueue showing wrong count after enqueues and dequeues"); } }
public void LinkedListQueue() { Random random = new Random(); LinkedListQueue <string> Stacklist = new LinkedListQueue <string>(); for (int i = 0; i < CountItems; i++) { Stacklist.Enqueue($"{i.ToString()}"); } for (int i = 0; i < CountItems; i++) { if (random.Next(i - RndMax, i + RndMin) == i) { Stacklist.Dequeue(); } } }
private void CompareMatch <T>(IEnumerable <T> expect) { var queue = new LinkedListQueue <T>(); foreach (var i in expect) { queue.Enqueue(i); } var actual = new List <T>(); while (!queue.IsEmpty) { var i = queue.Dequeue(); actual.Add(i); } expect.ToExpectedObject().ShouldMatch(actual); }
public void Can_dequeue_data() { var linkedListQueue = new LinkedListQueue <int>(); linkedListQueue.Enqueue(1); linkedListQueue.Enqueue(2); linkedListQueue.Enqueue(3); linkedListQueue.Enqueue(4); var dequeued = linkedListQueue.Dequeue(); Assert.Equal(1, dequeued.Data); Assert.Equal(3, linkedListQueue.Length); var head = linkedListQueue.Head; Assert.Equal(2, head.Data); Assert.Equal(3, head.Next.Data); Assert.Equal(4, head.Next.Next.Data); }
static void Main(string[] args) { LinkedListQueue<int> queue = new LinkedListQueue<int>(); for (int i = 1; i <= 5; i++) { queue.Enqueue(i); } Console.WriteLine("Count: {0}", queue.Count); Console.WriteLine("The peek is {0}", queue.Peek()); for (int i = 1; i <= 4; i++) { queue.Dequeue(); } Console.WriteLine("After dequeue 4 item the peek is {0}", queue.Peek()); }
public void BreadthFirstSearch(Action <K, T> action) { var queue = new LinkedListQueue <Node <K, T> >().Enqueue(root); while (!queue.IsEmprty()) { var currentNode = queue.Dequeue(); action.Invoke(currentNode.Key, currentNode.Value); if (!queue.Contains(currentNode.Left) && currentNode.Left == null) { queue.Enqueue(currentNode.Left); } if (!queue.Contains(currentNode.Right) && currentNode.Right == null) { queue.Enqueue(currentNode.Right); } } }
public void TestLinkedListQueueDequeue_ThrowsException() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); }
public void TestLinkedListQueueDequeue_ThrowsException() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); }
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(); }
public void Dequeue_ShouldBeOneValue() { Assert.Equal(oneValue, queue.Dequeue()); }
public void E1329() { LinkedListQueue<string> queue = new LinkedListQueue<string>(); Assert.AreEqual(0, queue.Size); queue.Enqueue(new Node<string>(1)); Assert.AreEqual(1, queue.Size); queue.Enqueue(new Node<string>(2)); Assert.AreEqual(2, queue.Size); queue.Enqueue(new Node<string>(3)); Assert.AreEqual(3, queue.Size); queue.Dequeue(); Assert.AreEqual(2, queue.Size); queue.Dequeue(); Assert.AreEqual(1, queue.Size); queue.Dequeue(); Assert.AreEqual(0, queue.Size); Assert.IsTrue(queue.IsEmpty()); try { queue.Dequeue(); throw new ApplicationException("Test failed"); } catch (Exception) { } }
public void TestLinkedListQueuePeek_ThrowsException() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Peek(); }
public void SortByDroid() { LinkedListStack<AstromechDroid> astromechList = new LinkedListStack<AstromechDroid>(); LinkedListStack<JanitorDroid> janitorList = new LinkedListStack<JanitorDroid>(); LinkedListStack<ProtocolDroid> protocolList = new LinkedListStack<ProtocolDroid>(); LinkedListStack<UtilityDroid> utilityList = new LinkedListStack<UtilityDroid>(); LinkedListQueue<IDroid> tempList = new LinkedListQueue<IDroid>(); foreach(Droid d in droidCollection) { if(d is AstromechDroid) { astromechList.Add((AstromechDroid)d); } else if(d is JanitorDroid) { janitorList.Add((JanitorDroid)d); } else if(d is ProtocolDroid) { protocolList.Add((ProtocolDroid)d); } else if(d is UtilityDroid) { utilityList.Add((UtilityDroid)d); } } while(astromechList.lastNode.Tail != null) { tempList.Enqueue(astromechList.PopOff()); } tempList.Enqueue(astromechList.PopOff()); while(janitorList.lastNode.Tail != null) { tempList.Enqueue(janitorList.PopOff()); } tempList.Enqueue(janitorList.PopOff()); while(protocolList.lastNode.Tail != null) { tempList.Enqueue(protocolList.PopOff()); } tempList.Enqueue(protocolList.PopOff()); while(utilityList.lastNode.Tail != null) { tempList.Enqueue(utilityList.PopOff()); } tempList.Enqueue(utilityList.PopOff()); droidCollection = new IDroid[lengthOfCollection]; int counter = 0; while(counter < lengthOfCollection) { if(tempList.lastNode != null) { droidCollection[counter] = tempList.Dequeue(); counter++; } } }