本文整理汇总了C#中Queue.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.isEmpty方法的具体用法?C# Queue.isEmpty怎么用?C# Queue.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.isEmpty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Main
// try out the ADT Queue using static allocation
public static void Main()
{
Queue q = new Queue();
Console.Write("Inserting ints from 9 to 1 into queue gives:\n");
for (int i = 9; i > 0; --i) {
q.enQueue( i);
}
q.display();
if (!q.isEmpty())
{
Console.Write("Deleting value {0} from front of queue", q.deQueue());
}
Console.Write("\nAdding value {0} to back of queue", 27);
q.enQueue(27);
q.display();
}
示例3: TestMethodisEmpty
public void TestMethodisEmpty() {
Queue<String> queue = new Queue<String>();
Assert.IsFalse(queue.isEmpty());
}
示例4: Bfs
// Method for breadth-first traversal.
// mode = 1 - normal traversal.
// mode = 2 - vertex colouring.
//
public void Bfs(int start, int mode = 1)
{
// Initialize the queue for the traversal.
//
Queue<int> q = new Queue<int>();
InitializeSearch();
// Insert a first vertex in the queue.
//
q.Enqueue(start);
discovered[start] = true;
// In loop, while queue is not empty.
//
while (!q.isEmpty())
{
// Take a next vertex out the queue.
//
var v = q.Dequeue();
// Make an action before traversal.
//
ProcessVertexEarly(v, mode);
// Start traversal in the neighborhoods.
//
var p = edges[v];
// In loop, while adjacency list is not null.
//
while (p != null)
{
// Take the next adjacent vertex.
//
var y = p.y;
// If it is not processed or the graph is directed, then is it new edge.
//
if (processed[y] == false || directed == true)
{
ProcessEdge(v, y, mode);
}
// If it is not opened, add in the queue.
//
if (discovered[y] == false)
{
q.Enqueue(y);
// Mark vertex as open.
//
discovered[y] = true;
// Add parent vertex into the relationship array.
//
parent[y] = v;
}
// Go to next vertex.
//
p = p.next;
}
// Mark the current vertex as processed.
//
processed[v] = true;
// Make an action after traversal.
//
ProcessVertexLate(v, mode);
}
isBfs = true;
}
示例5: BF
public void BF(int s)
{
id = 0;
visited = new int[V + 1];
int v, u;
Node t;
for (v = 1; v <= V; v++)
visited[v] = 0;
Queue q = new Queue();
q.enQueue(s);
while (!q.isEmpty())
{
v = q.deQueue();
if (visited[v] == 0)
{
visited[v] = ++id;
Console.WriteLine("Visiting Node {0} ", toChar(v));
for (t = adj[v]; t != t.next; t = t.next)
{
u = t.vert;
if (visited[u] == 0)
q.enQueue(u);
}
}
}
}