本文整理汇总了C#中LinkedQueue.Enqueue方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedQueue.Enqueue方法的具体用法?C# LinkedQueue.Enqueue怎么用?C# LinkedQueue.Enqueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedQueue
的用法示例。
在下文中一共展示了LinkedQueue.Enqueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
LinkedQueue<int> linkedQueue = new LinkedQueue<int>();
LinkedQueue<string> anotherLinkedQueue = new LinkedQueue<string>(
new List<string> { "pesho", "gosho", "sasho", "misho" });
Console.WriteLine(anotherLinkedQueue);
Console.WriteLine("First: " + anotherLinkedQueue.First.Value);
Console.WriteLine("Last: " + anotherLinkedQueue.Last.Value);
Console.WriteLine();
linkedQueue.Enqueue(15);
linkedQueue.Enqueue(20);
Console.WriteLine(linkedQueue);
linkedQueue.Enqueue(50);
linkedQueue.Enqueue(100);
Console.WriteLine(linkedQueue);
anotherLinkedQueue.Dequeue();
Console.WriteLine(anotherLinkedQueue);
linkedQueue.Dequeue();
Console.WriteLine(linkedQueue);
Console.WriteLine(linkedQueue.Peek());
anotherLinkedQueue.Clear();
Console.WriteLine(anotherLinkedQueue.Count == 0 && anotherLinkedQueue.First == null && anotherLinkedQueue.Last == null);
}
示例2: Main
static void Main()
{
try
{
LinkedQueue<string> queue = new LinkedQueue<string>();
queue.Enqueue("Message One");
queue.Enqueue("Message Two");
queue.Enqueue("Message Three");
queue.Enqueue("Message Four");
Console.WriteLine(queue.Peek());
Console.WriteLine(queue.Contains("Message Three"));
var array = queue.ToArray();
Console.WriteLine(string.Join(", ", array));
while (queue.Count > 0)
{
string message = queue.Dequeue();
Console.WriteLine(message);
}
queue.Dequeue();
}
catch (IndexOutOfRangeException iex)
{
Console.WriteLine(iex.TargetSite + " -> " + iex.Message);
}
catch (NullReferenceException nex)
{
Console.WriteLine(nex.TargetSite + " -> " + nex.Message);
}
}
示例3: TestLinkedQueue
private static void TestLinkedQueue()
{
ILinkedQueue<int> linkedQueue = new LinkedQueue<int>();
// Should return true
var isEmpty = linkedQueue.IsEmpty();
linkedQueue.Enqueue(1);
linkedQueue.Enqueue(2);
linkedQueue.Enqueue(3);
linkedQueue.Enqueue(4);
// Should have 4 elements
// Should remove first added element - (1) and return it
var removedElement = linkedQueue.Dequeue();
// Should return first element - (2)
var firstElement = linkedQueue.Peek();
// Should return 3
var count = linkedQueue.Count;
// Should return false
isEmpty = linkedQueue.IsEmpty();
}
示例4: Push_Pop_Two
public void Push_Pop_Two()
{
var ints = new LinkedQueue<int> ();
Assert.AreEqual (0, ints.Count);
int element1 = 1;
ints.Enqueue (element1);
Assert.AreEqual (1, ints.Count);
int element2 = 2;
ints.Enqueue (element2);
Assert.AreEqual (2, ints.Count);
{
int poppedEl = ints.Dequeue ();
Assert.AreEqual (poppedEl, element1);
Assert.AreEqual (1, ints.Count);
}
{
int poppedEl = ints.Dequeue ();
Assert.AreEqual (poppedEl, element2);
Assert.AreEqual (0, ints.Count);
}
}
示例5: EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly
public void EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly()
{
//Arrange
var queue = new LinkedQueue<int>();
//Assert
Assert.AreEqual(0, queue.Count);
//Act
queue.Enqueue(5);
//Assert
Assert.AreEqual(1, queue.Count);
//Act
queue.Enqueue(6);
//Assert
Assert.AreEqual(2, queue.Count);
//Act
var element = queue.Dequeue();
//Assert
Assert.AreEqual(5, element);
Assert.AreEqual(1, queue.Count);
//Act
element = queue.Dequeue();
//Assert
Assert.AreEqual(6, element);
Assert.AreEqual(0, queue.Count);
}
示例6: Main
static void Main()
{
// TODO: Epxlain the tests
Console.WriteLine("Testing custom queue class.");
Console.WriteLine("Class features:");
Console.WriteLine(" - linked list implementation");
Console.WriteLine(" - methods Enqueue, Dequeue, Peek, Contains and property Count.");
Console.WriteLine();
Console.WriteLine("Creating a LinkedQueue.");
LinkedQueue<int> queue = new LinkedQueue<int>();
Console.WriteLine("DONE!" + Environment.NewLine);
Console.WriteLine("Enqueuing numbers from 1 to 10");
for (int i = 1; i <= 10; i++)
{
queue.Enqueue(i);
}
Console.WriteLine("DONE!" + Environment.NewLine);
Console.WriteLine("Printing queue using custom enumerator:");
Print(queue);
Console.WriteLine("Peeking: " + queue.Peek());
Console.WriteLine();
Console.WriteLine("Dequeuing 7 elements");
for (int i = 0; i < 7; i++)
{
queue.Dequeue();
}
Console.Write("Press any key to continue testing.");
Console.ReadKey();
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
Console.WriteLine("Enqueuing numbers from 1 to 10");
for (int i = 1; i <= 10; i++)
{
queue.Enqueue(i);
}
Console.WriteLine("Peeking: " + queue.Peek());
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
Console.WriteLine("Cheking if queue contains the number 5: " + queue.Contains(5));
Console.WriteLine("Cheking if queue contains the number -15: " + queue.Contains(-15));
Console.WriteLine();
Console.WriteLine("Clearing the queue");
queue.Clear();
Console.WriteLine("Cleared");
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
try
{
Console.WriteLine("Peeking: ");
queue.Peek();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例7: Main
static void Main()
{
LinkedQueue<int> myQueue = new LinkedQueue<int>();
myQueue.Enqueue(5);
myQueue.Enqueue(6);
Console.WriteLine(myQueue.Dequeue());
Console.WriteLine(myQueue.Dequeue());
}
示例8: TestCountAfterEnqueue
public void TestCountAfterEnqueue()
{
var queue = new LinkedQueue<int>();
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);
Assert.AreEqual(3, queue.Count);
}
示例9: Main
public static void Main()
{
LinkedQueue<int> sue = new LinkedQueue<int>();
sue.Enqueue(5);
sue.Enqueue(1);
sue.Enqueue(7);
sue.Dequeue();
}
示例10: Main
static void Main(string[] args)
{
var linkedQueue = new LinkedQueue<int>();
linkedQueue.Dequeue();
linkedQueue.Enqueue(5);
linkedQueue.Enqueue(6);
linkedQueue.Enqueue(7);
Console.WriteLine(string.Join(" ",linkedQueue.ToArray()));
}
示例11: Dequeue_ShouldDecrementCount
public void Dequeue_ShouldDecrementCount()
{
var queue = new LinkedQueue<int>();
queue.Enqueue(5);
queue.Enqueue(7);
queue.Dequeue();
Assert.AreEqual(1, queue.Count, "Dequeue isn't working correctly.");
}
示例12: TestCount_SingleElement_CountOne
public void TestCount_SingleElement_CountOne()
{
var queue = new LinkedQueue<int>();
queue.Enqueue(50);
queue.Enqueue(60);
queue.Enqueue(70);
queue.Enqueue(int.MaxValue);
Assert.AreEqual(4, queue.Count, "Queue count should be 4.");
}
示例13: DequeueElementFromLinkedStackShouldReturnTheLastElement
public void DequeueElementFromLinkedStackShouldReturnTheLastElement()
{
LinkedQueue<int> arrayStack = new LinkedQueue<int>();
arrayStack.Enqueue(1);
arrayStack.Enqueue(2);
arrayStack.Enqueue(3);
var lastElement = arrayStack.Dequeue();
Assert.AreEqual(3, lastElement);
}
示例14: To_Array
public void To_Array()
{
var nums = new LinkedQueue<int>();
nums.Enqueue(3);
nums.Enqueue(5);
nums.Enqueue(-2);
nums.Enqueue(7);
int[] arrTest = { 3, 5, -2, 7 };
CollectionAssert.AreEqual(arrTest, nums.ToArray());
}
示例15: DequeueTest_CheckTheExpectedCount
public void DequeueTest_CheckTheExpectedCount()
{
LinkedQueue<int> queue = new LinkedQueue<int>();
queue.Enqueue(45);
queue.Enqueue(32);
queue.Enqueue(1);
Assert.AreEqual(3, queue.Count, "Count is not the same as expected after the Enqueue");
}