static void Main() { MyQueue<int> numbers = new MyQueue<int>(); for (int i = 1; i < 5; i++) { numbers.Enqueue(i); } int firstElement = numbers.Peek(); Console.WriteLine(firstElement); // There is some bug with the dequeue that i need to find //numbers.Dequeue(); try { foreach (var number in numbers) { Console.WriteLine(number); } } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { MyQueue<int> queue = new MyQueue<int>(); queue.Enqueue(5); queue.Enqueue(15); queue.Enqueue(-9999); queue.Enqueue(11); queue.Enqueue(135); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Count); Console.WriteLine(); Console.WriteLine(queue.ToString()); Console.WriteLine(); foreach (var elem in queue) { Console.WriteLine(elem); } Console.WriteLine(); queue.Clear(); Console.WriteLine(queue.Count); Console.WriteLine(queue.Dequeue()); }
static void Main(string[] args) { MyQueue<int> myIntQueue = new MyQueue<int>(5); try { myIntQueue.Enqueue(1); myIntQueue.Enqueue(2); myIntQueue.Enqueue(3); myIntQueue.Enqueue(4); myIntQueue.Enqueue(5); } catch (MyQueueIsFullException e) { Console.WriteLine(e.Message); } try { Console.WriteLine(myIntQueue.Dequeue()); Console.WriteLine(myIntQueue.Dequeue()); Console.WriteLine(myIntQueue.Dequeue()); Console.WriteLine(myIntQueue.Dequeue()); Console.WriteLine(myIntQueue.Dequeue()); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadKey(); }
/// <summary> /// Sorts the droids based on model /// </summary> /// <param name="toSort"></param> public void SortModel(List<Droid> toSort) { MyStack<UtilityDroid> utilityStack = new MyStack<UtilityDroid>(); MyStack<AstromechDroid> astroStack = new MyStack<AstromechDroid>(); MyStack<ProtocolDroid> protoStack = new MyStack<ProtocolDroid>(); MyStack<JanitorDroid> janitorStack = new MyStack<JanitorDroid>(); //Separates the List based on class foreach (Droid d in toSort) { if (d is AstromechDroid) astroStack.Add((AstromechDroid)d); else if (d is JanitorDroid) janitorStack.Add((JanitorDroid)d); else if (d is UtilityDroid) utilityStack.Add((UtilityDroid)d); else if (d is ProtocolDroid) protoStack.Add((ProtocolDroid)d); } // puts the stacks into a Queue MyQueue<Droid> tmpQue = new MyQueue<Droid>(); while (astroStack.Count > 0) tmpQue.Add(astroStack.Get()); while (janitorStack.Count > 0) tmpQue.Add(janitorStack.Get()); while (utilityStack.Count > 0) tmpQue.Add(utilityStack.Get()); while (protoStack.Count > 0) tmpQue.Add(protoStack.Get()); //Relies on the fact that a list is a reference object toSort.Clear(); while (tmpQue.Count > 0) toSort.Add(tmpQue.Get()); }
public void ShouldEnqueueAndDequeue() { var queue = new MyQueue<string>(); var expected = "abc"; queue.Enqueue(expected); Assert.AreEqual(expected, queue.Dequeue()); }
public PlanetChecker(IMyCubeGrid grid) { this.m_logger = new Logger(GetType().Name, grid.getBestName, ClosestPlanet.getBestName, CurrentState.ToString); this.m_grid = grid; this.m_cells = new MyQueue<Vector3I>(8); this.m_cellsUnique = new HashSet<Vector3I>(); }
static void Main(string[] args) { MyQueue<int> queue = new MyQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Dequeue(); Console.WriteLine(queue.Contains(1)); }
public void ShouldReturnQueueCount() { var queue = new MyQueue<string>(); Assert.AreEqual(0, queue.Count); queue.Enqueue("abc"); queue.Enqueue("abc"); Assert.AreEqual(2, queue.Count); }
public void Should_Enqueue_Multiple_Items_To_MyQueue_Instance() { var myQueue = new MyQueue<object>(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); myQueue.Enqueue(4); Assert.AreEqual(4, myQueue.Count); }
protected void Application_Start(object sender, EventArgs e) { if (Application["queue"] == null) { Application.Remove("queue"); Application["queue"] = new MyQueue<string>(); } }
public void ContainsTest() { MyQueue<int> actualInts = new MyQueue<int>(); actualInts.Enqueue(5); bool actual = actualInts.Contains(5); Assert.AreEqual(true, actual); }
public static void Main() { MyQueue<int> myQueue = new MyQueue<int>(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); myQueue.Dequeue(); Console.WriteLine(string.Join(" ,", myQueue.Objects)); }
public void TestingPeek2() { MyQueue <int> queue = new MyQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Dequeue(); Assert.AreEqual(queue.Peek(), 2); }
/// <summary> /// Добавление элемента в очередь /// </summary> /// <param name="queue"></param> private void AddInQueue(ref MyQueue <int> queue) { var answer = GetAnswer(); if (answer == null) { return; } queue.Enqueue(answer.Value); }
/// <summary> /// Инициализация очереди /// </summary> /// <returns></returns> protected virtual MyQueue <int> InitQueue() { var queue = new MyQueue <int>((int)ValueCount); for (var i = 0; i < ValueCount; i++) { queue.Enqueue(RandomValue()); } return(queue); }
private static void TestMyQueue() { MyQueue<int> foo = new MyQueue<int>(); foo.Enqueue(1); foo.Enqueue(2); foo.Enqueue(3); Console.WriteLine(foo.Dequeue()); Console.WriteLine(foo.Dequeue()); Console.WriteLine(foo.Dequeue()); }
/// <summary> /// Проверка на заполненность /// </summary> /// <param name="queue"></param> private void CheckQueueFull(MyQueue <int> queue) { if (queue.IsFull) { Console.WriteLine("Очередь заполнена!"); } else { Console.WriteLine("Очередь не заполнена..."); } }
public void CanAddSeveralItems() { var queue = new MyQueue <int>(); queue.Enqueue(1); queue.Enqueue(1); queue.Enqueue(1); queue.Enqueue(1); queue.Enqueue(1); Assert.Equal(5, queue.Count); }
public void WillHoldMoreThan10Items() { var queue = new MyQueue <int>(); for (var i = 0; i < 100; i++) { queue.Enqueue(i); } Assert.Equal(100, queue.Count); }
static void Main(string[] args) { var q = new MyQueue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4); Console.WriteLine(q.front.key); }
public DriveAndHike(MyQueue <Trip> trips) { if (trips == null) { Trips = new MyQueue <Trip>(); } else { Trips = trips; } }
public void Queue_Is_Empty() { var queue = new MyQueue <int>(); var isEmpty = queue.IsEmpty(); Assert.True(isEmpty); Assert.Equal(0, queue.Length); Assert.Null(queue.First); Assert.Null(queue.Last); }
public void ShouldBeFIFO() { var queue = new MyQueue<string>(); queue.Enqueue("first"); queue.Enqueue("second"); queue.Enqueue("third"); Assert.AreEqual("first", queue.Dequeue()); Assert.AreEqual("second", queue.Dequeue()); Assert.AreEqual("third", queue.Dequeue()); }
public void Enqueue_Two_Elements() { var queue = new MyQueue <int>(); queue.Enqueue(10); queue.Enqueue(20); Assert.Equal(2, queue.Length); Assert.Equal(10, queue.First.Value); Assert.Equal(20, queue.Last.Value); }
/// <summary> /// 添加并行循环动画列表 /// </summary> /// <param name="target">目标物体</param> /// <param name="animDatas">动画列表</param> public void AddItemQueueInList(Transform target, List <AnimData> animDatas) { MyQueue <Item> items = new MyQueue <Item>(); animDatas.ForEach(data => items.Add(new Item() { amountTime = data.Duration, action = data.Lerp(target) })); itemQueueList.Add(items); }
static void Main(string[] args) { MyQueue myQueue = new MyQueue(1); myQueue.Add(25); Console.WriteLine(myQueue.Get()); MyStack myStack = new MyStack(1); myStack.Push(35); Console.WriteLine(myStack.Pop()); }
public void BreadthFirstOrderTraversal <T>(TreeNode rootNode) { if (rootNode != null) { MyQueue <TreeNode> queue = new MyQueue <TreeNode>(); queue.Enqueue(rootNode); BFS(rootNode, queue); } }
public MyCachingDynamicObjectsPool(int poolSize, int cacheSize, int poolGrowth) { m_cacheSize = cacheSize; m_poolGrowth = poolGrowth; m_cache = new Dictionary <ObjectKey, ObjectType>(m_cacheSize); m_objectPool = new Stack <ObjectType>(poolSize); m_entryAge = new MyQueue <ObjectKey>(m_cacheSize); Restock(poolSize); }
public void TestEnqueue_ToFullShiftedQueue_Queue() { var queue = new MyQueue <int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); queue.Dequeue(); var expected = new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; queue.Enqueue(expected[expected.Length - 1]); CollectionAssert.AreEqual(expected, queue); }
public void CanSuccessfullydDequeueOutOfAQueueTheExpectedValue() { MyQueue <string> queue = new MyQueue <string>(); queue.Enqueue("Are"); queue.Enqueue("You"); queue.Dequeue(); string expected = queue.Front.Value; Assert.Equal("You", expected); }
public void Dequeue_Dequeue3FromQueue_3Returned() { var queue = new MyQueue <int>(); queue.Enqueue(3); queue.Enqueue(6); var num = queue.Dequeue(); Assert.AreEqual(3, num); }
public void Returns_First_Item() { var queue = new MyQueue <int> { 1, 2, 3, 4, 5 }; int expected = 1; int actual = queue.Get(); Assert.AreEqual(expected, actual); }
public void Contains_QueueContains6_FalseReturned() { var queue = new MyQueue <int>(); queue.Enqueue(-3); queue.Enqueue(-6); var flag = queue.Contains(6); Assert.IsFalse(flag); }
private void btnAdd_Click(object sender, EventArgs e) { tbShow.Text = ""; string element = tbElement.Text; queue = queue.Solution(queue, element); foreach (string el in queue) { tbShow.Text += el + " "; } }
public void TestPeek() { //TestPush 3 items, checked Count MyQueue Q = new MyQueue(3); Q.Enqueue(1); Q.Enqueue(2); Q.Enqueue(3); Assert.AreEqual(3, Q.Peek()); Assert.AreEqual(3, Q.Count()); }
private static void ReverseQueue(QueueTasks queueTasks) { MyQueue <int> queue = new MyQueue <int>(); queue.Insert(1); queue.Insert(2); queue.Insert(3); queue.Insert(4); MyQueue <int> Revqueue = queueTasks.ReverseQueue(queue); }
public void QueuePush3ItemGetCount() { int maxSize = 100; var myQueue = new MyQueue(maxSize); myQueue.Push(1); myQueue.Push("1"); myQueue.Push("A"); Assert.AreEqual(3, myQueue.GetCount()); }
static void Main(string[] args) { // https://leetcode.com/problems/implement-queue-using-stacks/ MyQueue myQueue = new MyQueue(); myQueue.Push(1); // queue is: [1] myQueue.Push(2); // queue is: [1, 2] (leftmost is front of the queue) myQueue.Peek(); // return 1 myQueue.Pop(); // return 1, queue is [2] myQueue.Empty(); // return false }
public void Peek_An_Element_In_A_Queue_With_No_Element() { var queue = new MyQueue <int>(); var item = queue.Peek(); Assert.Equal(0, item); Assert.Equal(0, queue.Length); Assert.Null(queue.First); Assert.Null(queue.Last); }
public void Clear_ClearQueue_QueueIsEmpty() { var queue = new MyQueue <int>(); queue.Enqueue(3); queue.Enqueue(-2); queue.Clear(); CollectionAssert.IsEmpty(queue); }
public void CanGetTheSizeOfQueue() { MyQueue <string> queue = new MyQueue <string>(); queue.Enqueue("Are"); queue.Enqueue("You"); queue.Enqueue("23"); int actual = queue.Size; Assert.Equal(3, actual); }
static void Main(string[] args) { MyQueue<int> myqueue = new MyQueue<int>(); myqueue.add(1); myqueue.add(2); myqueue.add(3); myqueue.remove(); Console.WriteLine(myqueue.peek()); myqueue.add(4); myqueue.add(5); Console.WriteLine(myqueue.peek()); }
public void TestMethodPeek() { MyQueue q = new MyQueue(5); q.Enqueue("a"); q.Enqueue("b"); q.Enqueue("c"); q.Enqueue("d"); q.Enqueue("e"); Assert.AreEqual("a", q.Peek()); Assert.AreEqual(5, q.Count()); }
public void TestMethodClear() { MyQueue q = new MyQueue(5); q.Enqueue("a"); q.Enqueue("b"); q.Enqueue("c"); q.Enqueue("d"); q.Enqueue("e"); q.Clear(); Assert.AreEqual(0, q.Count()); }
public static void Main() { var queue = new MyQueue<int>(1); queue.Enqueue(3); queue.Enqueue(5); queue.Enqueue(4); Console.WriteLine(queue.Peek()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); }
public void PopItemShouldBeLastItemPushed() { var myQueue = new MyQueue <string>(); myQueue.Push("Test1"); myQueue.Push("Test2"); myQueue.Push("Test3"); var item = myQueue.Pop(); Assert.That(item, Is.EqualTo("Test3")); Assert.That(myQueue[0], Is.EqualTo("Test2")); }
static void Main() { MyQueue<int> test = new MyQueue<int>(); test.Enqueue(1); test.Enqueue(9); test.Enqueue(3); test.Enqueue(999); Console.WriteLine(test.Count); Console.WriteLine(test.Dequeue()); Console.WriteLine(test.Dequeue()); Console.WriteLine(test.Count); }
public void ClearTest() { MyQueue<int> actualInts = new MyQueue<int>(); for (int i = 1; i <= 5; i++) { actualInts.Enqueue(i); } actualInts.Clear(); Assert.AreEqual(0, actualInts.Count); }
public void Should_Dequeue_Single_Item_From_MyQueue_Instance() { var myQueue = new MyQueue<object>(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); var dequeueResult = myQueue.Dequeue(); myQueue.Enqueue(4); Assert.AreEqual(3, myQueue.Count); Assert.AreEqual(1, dequeueResult); }
public void PeekTest() { MyQueue<int> actualInts = new MyQueue<int>(); for (int i = 1; i <= 5; i++) { actualInts.Enqueue(i); } int actual = actualInts.Peek(); Assert.AreEqual(5, actualInts.Count); Assert.AreEqual(1, actual); }
static void Main(string[] args) { var queue = new MyQueue<int>(1); var queu2 = new Queue<int>(); queue.Enqueue(3); queue.Enqueue(5); queue.Enqueue(4); System.Console.WriteLine(queue.Peek()); System.Console.WriteLine(queue.Dequeue()); System.Console.WriteLine(queue.Dequeue()); }
public void Should_Dequeue_All_Items_From_MyQueue_Instance() { var myQueue = new MyQueue<object>(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); var dequeueResult1 = myQueue.Dequeue(); var dequeueResult2 = myQueue.Dequeue(); var dequeueResult3 = myQueue.Dequeue(); Assert.AreEqual(1, dequeueResult1); Assert.AreEqual(2, dequeueResult2); Assert.AreEqual(3, dequeueResult3); Assert.AreEqual(0, myQueue.Count); }
static void Main(string[] args) { MyQueue<int> queue = new MyQueue<int>(); queue.Push(10); queue.Push(20); queue.Push(30); queue.Push(new int[] { 40, 50, 60 }); Console.WriteLine("Elements in random order:"); while (!queue.IsEmpty) { Console.WriteLine(queue.Pop()); } Console.ReadKey(); }
public static void Main() { var queue = new MyQueue<int>(); queue.Enqueue(5); queue.Enqueue(8); queue.Enqueue(15); queue.Enqueue(243); queue.Enqueue(13); Console.WriteLine("Deque element {0}", queue.Dequeue()); Console.WriteLine("Peek element {0}", queue.Peek()); foreach (var element in queue) { Console.WriteLine("{0} ", element); } }
public void EnqueueTest() { MyQueue<int> actualInts = new MyQueue<int>(); for (int i = 1; i <= 5; i++) { actualInts.Enqueue(i); } string actual = ""; foreach (var item in actualInts) { actual += item.ToString() + " "; } Assert.AreEqual(5, actualInts.Count); Assert.AreEqual("1 2 3 4 5 ", actual); }
public static void Main() { MyQueue<int> queue = new MyQueue<int>(); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Enqueue(6); queue.Enqueue(6); queue.Enqueue(6); queue.Enqueue(6); queue.Enqueue(6); queue.Enqueue(6); queue.Enqueue(6); while (queue.Count > 0) { Console.WriteLine(queue.Dequeue()); } }
static void Main() { var queue = new MyQueue<string>(); queue.Enqueue("First"); queue.Enqueue("Second"); queue.Enqueue("Third"); queue.Enqueue("Fourth"); Console.WriteLine(queue.Peek); // First Console.WriteLine(queue.Dequeue()); // First Console.WriteLine(queue.Dequeue()); // Second Console.WriteLine(queue.Peek); // Third Console.WriteLine(queue.Dequeue()); // Third Console.WriteLine(queue.Dequeue()); // Fourth Console.WriteLine(queue.Dequeue()); // IndexOutOfRangeException: The Queue is empty }
public Form1() { InitializeComponent(); firstThread = new Thread(RunFirstThread); secondThread = new Thread(RunSecondThread); variableForExcep = false; isStopWorkMethod = false; queueOfMessages = new MyQueue(); queueOfMessages.OnRaisedException += queueOfMessages_OnRaisedException; manualResetEvent = new ManualResetEvent(false); firstThread.Name = "FIRST"; secondThread.Name = "SECOND"; firstThread.IsBackground = true; secondThread.IsBackground = true; firstThread.Start(); secondThread.Start(); }
static void Main(string[] args) { MyQueue<int> queu = new MyQueue<int>(4); queu.Enqueue(18); queu.Enqueue(12); queu.Enqueue(321); queu.Enqueue(2); queu.Dequeue(); int[] arr = queu.ToArray(); Console.WriteLine(String.Join(",", arr)); //Console.WriteLine(queu.Contains(2)); //queu.Clear(); // var value = queu.Dequeue(); // value = queu.Dequeue(); // Console.WriteLine(value); //Console.WriteLine(queu.Count); //foreach (var item in queu) //{ // Console.WriteLine(item); //} }
public static void RunTests() { MyQueue queue = new MyQueue(5); queue.Enqueue(5); Console.WriteLine(queue.Size()); queue.Enqueue(6); Console.WriteLine(queue.Size()); queue.Enqueue(7); Console.WriteLine(queue.Size()); queue.Enqueue(3); Console.WriteLine(queue.Size()); queue.Enqueue(2); Console.WriteLine(queue.Size()); queue.Enqueue(1); Console.WriteLine(queue.Size()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Size()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Dequeue()); Console.WriteLine(queue.Size()); }