本文整理汇总了C#中Queue.Pop方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Pop方法的具体用法?C# Queue.Pop怎么用?C# Queue.Pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Pop方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTest
public static void DoTest ()
{
string top;
Queue<string> queue = new Queue<string>();
queue.Enqueue("aaa");
queue.Enqueue("bbb");
queue.Enqueue("ccc");
queue.Enqueue("ddd");
queue.Enqueue("eee");
queue.Enqueue("fff");
queue.Enqueue("ggg");
queue.Enqueue("hhh");
Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());
var array = queue.ToArray();
Debug.Assert (array.Length == 8, "Wrong size.");
queue.Pop();
queue.Pop();
top = queue.Dequeue();
Console.WriteLine("Old 3nd-last: " + top + "\r\n");
Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());
queue.Pop();
queue.Pop();
Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());
var array2 = queue.ToArray();
Debug.Assert (array2.Length == 3, "Wrong size.");
}
示例2: CountTest
public void CountTest()
{
var queue = new Queue<int>();
queue.Push(1);
queue.Push(2);
Assert.That(queue.Count, Is.EqualTo(2));
queue.Pop();
queue.Pop();
Assert.That(queue.Count, Is.EqualTo(0));
}
示例3: FrontTest
public void FrontTest()
{
var queue = new Queue<int>();
queue.Push(1);
queue.Push(2);
Assert.That(queue.Front, Is.EqualTo(1));
queue.Pop();
Assert.That(queue.Front, Is.EqualTo(2));
queue.Pop();
Assert.Throws<InvalidOperationException>(delegate { int a = queue.Front; });
}
示例4: PopAndPush_LoopQueue
public void PopAndPush_LoopQueue()
{
int capacity = 3;
Queue<int> queue = new Queue<int>(capacity);
int[] expectedQueue = { 1, 4, 5 };
queue.Push(3);
queue.Push(2);
queue.Push(1);
queue.Pop();
queue.Push(4);
queue.Pop();
queue.Push(5);
Assert.AreEqual(capacity, queue.Capacity, "Capacity is increased!");
CollectionAssert.AreEqual(expectedQueue, queue.GetElements());
}
示例5: QueueTest
static void QueueTest()
{
Queue<int> q = new Queue<int>();
q.Push(1);
q.Push(2);
q.Push(3);
q.Push(4);
while (q.Length > 0)
{
Console.WriteLine(q.Pop());
}
}
示例6: Pop_5_Integers
public void Pop_5_Integers()
{
var expected = new int[] { 0, 1, 2, 3, 4 };
Queue<int> queue = new Queue<int>();
for (var i = 0; i < 5; i++)
{
queue.Push(i);
}
var actual = new int[5];
for (var i = 0; i < 5; i++)
{
actual[i] = queue.Pop();
}
CollectionAssert.AreEqual(expected, actual);
}
示例7: Main
public static int Main()
{
string cmd;
int val;
Queue<int> q = new Queue<int>();
while (true)
{
Console.WriteLine();
Console.WriteLine("Commands: push, pop, front, length, print, exit");
Console.Write("? ");
cmd = Console.ReadLine();
try
{
if (cmd == "push")
{
Console.Write("Value: ");
val = Int32.Parse(Console.ReadLine());
q.Push(val);
}
else if (cmd == "pop")
{
q.Pop();
Console.WriteLine("first element is deleted");
}
else if (cmd == "front")
Console.WriteLine(q.Front());
else if (cmd == "length")
Console.WriteLine(q.Length);
else if (cmd == "exit")
break;
else if (cmd == "print")
q.Print();
else
Console.WriteLine("Incorrect command");
}
catch (EmptyQueue)
{
Console.WriteLine("Empty queue");
}
Console.WriteLine();
}
return 0;
}
示例8: ShortestPath
public static int ShortestPath(Vertex start, Vertex end)
{
Queue<Vertex> queue = new Queue<Vertex>(10);
if (start == null || end == null)
return 0;
start.Status = Color.Grey;
queue.Push(start);
Vertex cur = null;
while (!queue.IsEmpty())
{
cur = queue.Pop();
if (cur == end)
{
break;
}
foreach (Vertex v in cur.Neighbors)
{
if (v.Status == Color.White)
{
v.Status = Color.Grey;
v.Parent = cur;
v.Distance = cur.Distance + 1;
queue.Push(v);
}
}
cur.Status = Color.Black;
}
if (cur.Parent == null)
return 0;
else
return cur.Parent.Distance + 1;
}
示例9: Pop_NoElements_Exception
public void Pop_NoElements_Exception()
{
Queue<int> queue = new Queue<int>();
queue.Pop();
}
示例10: Pop_3214elements_3returned
public void Pop_3214elements_3returned()
{
Queue<int> queue = new Queue<int>();
queue.Push(3);
queue.Push(2);
queue.Push(1);
queue.Push(4);
int[] expectedQueue = {2, 1, 4};
int actualNumber = queue.Pop();
Assert.AreEqual(3, actualNumber);
CollectionAssert.AreEqual(expectedQueue, queue.GetElements());
}