本文整理汇总了C#中Queue.dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.dequeue方法的具体用法?C# Queue.dequeue怎么用?C# Queue.dequeue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.dequeue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(string src, string dest)
{
Queue<string> q = new Queue<string>();
q.enqueue(src);
dict["src"] = true;// I visited this node.
string temp= src;
List<string> res = new List<string>();
while (q.length!=0)
{
string word = q.dequeue();
//if(word == dest) break;
//create a new word and check into dictionary and add into queue
for (int i = 0; i < word.Length; i++)
{
for (int j = 0; i < 26; j++)
{
//creat a new word by replacing character at ith position
string newWord = word.Substring(0, i) + word[j] + word.Substring(i + 1); //w may be a dest
if (dict.ContainsKey(newWord) && dict["newWord"]==false)// newWord should not be visited, false means not visited before
{
q.enqueue(newWord);
res.Add(newWord);
temp = newWord;
break;
}
}
break;
}
}
}
示例2: Main
static void Main(string[] args)
{
Queue<int> list = new Queue<int>();
Console.WriteLine(list.isEmpty());
list.enqueue(0);
list.enqueue(5);
list.enqueue(7);
list.enqueue(-4);
list.enqueue(0);
Console.WriteLine(list.dequeue());
Console.WriteLine(list.dequeue());
Console.WriteLine(list.dequeue());
list.enqueue(9);
Console.WriteLine(list.dequeue());
Console.WriteLine(list.isEmpty());
Console.WriteLine(list.isEmpty());
list.nuke();
Console.WriteLine(list.isEmpty());
Console.ReadKey();
}
示例3: SortByType
public void SortByType()
{
//Bucket Sort
/*
A arry to be sorted
n is length of A
for i = 1 to n
insert A[i] into B bucket (queue)
for i = 0 to n-1
sort B
*/
//Generic Stack for each droid type
Stack<Droid> protocolStack = new Stack<Droid>();
Stack<Droid> utilityStack = new Stack<Droid>();
Stack<Droid> janitorStack = new Stack<Droid>();
Stack<Droid> astromechStack = new Stack<Droid>();
//Create a Queue for Droids
Queue<Droid> droidQueue = new Queue<Droid>();
//Create a linked list for the droids
LinkedList<Droid> droidLinkedList = new LinkedList<Droid>();
int n = droidCollection.Length;
//Move droid type into the bucket
foreach (int i in droidCollection)
{
//check if value is not null
if(droidCollection[i] != null)
{
//Add a droid to the linked list
droidLinkedList.AddLast(droidCollection);
}
//Add a new node for the data in the linked list
GenericNode<Droid> node = new GenericNode<Droid>();
node.Next;
droidQueue.enqueue(droidLinkedList);
}
//Push the droids into the queue(enqueue) and sort by pushing into their respected stacks
foreach (int i in droidQueue)
{
switch (droidQueue.Equals)
{
case "Protocol":
//take out of queue
//Add to the respected stack
protocolStack.push(droidQueue.dequeue());
break;
case "Utility":
utilityStack.push(droidQueue.dequeue());
break;
case "Janitor":
droidQueue.dequeue();
janitorStack.push(droidQueue.dequeue());
break;
case "Astromech":
droidQueue.dequeue();
astromechStack.push(droidQueue.dequeue());
break;
}
}
}