本文整理汇总了C#中Queue.Enqueue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Enqueue方法的具体用法?C# Queue.Enqueue怎么用?C# Queue.Enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Enqueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollectEntities
private void CollectEntities(int addr, Dictionary<int, Entity> list)
{
int num = addr;
addr = M.ReadInt(addr + 4);
var hashSet = new HashSet<int>();
var queue = new Queue<int>();
queue.Enqueue(addr);
while (queue.Count > 0)
{
int nextAddr = queue.Dequeue();
if (hashSet.Contains(nextAddr))
continue;
hashSet.Add(nextAddr);
if (M.ReadByte(nextAddr + 21) == 0 && nextAddr != num && nextAddr != 0)
{
int key = M.ReadInt(nextAddr + 12);
if (!list.ContainsKey(key))
{
int address = M.ReadInt(nextAddr + 16);
var entity = base.GetObject<Entity>(address);
list.Add(key, entity);
}
queue.Enqueue(M.ReadInt(nextAddr));
queue.Enqueue(M.ReadInt(nextAddr + 8));
}
}
}
示例2: FindSequence
// 09. We are given the following sequence:
// S1 = N;
// S2 = S1 + 1;
// S3 = 2*S1 + 1;
// S4 = S1 + 2;
// S5 = S2 + 1;
// S6 = 2*S2 + 1;
// S7 = S2 + 2;
// ...
// Using the Queue<T> class write a program to print its first 50 members for given N.
// Example: N=2 2, 3, 5, 4, 4, 7, 5, 6, 11, 7, 5, 9, 6, ...
public static void FindSequence(int startNumber)
{
Queue<int> sequence = new Queue<int>();
Queue<int> tempSequence = new Queue<int>();
int S1 = startNumber;
int S2;
int S3;
int S4;
sequence.Enqueue(S1);
for (int i = 0; i < 50; i+=3)
{
S2 = S1 + 1;
S3 = 2*S1 + 1;
S4 = S1 + 2;
sequence.Enqueue(S2);
sequence.Enqueue(S3);
sequence.Enqueue(S4);
tempSequence.Enqueue(S2);
tempSequence.Enqueue(S3);
tempSequence.Enqueue(S4);
S1 = tempSequence.Dequeue();
}
for (int i = 0; i < 50; i++)
{
Console.Write(sequence.Dequeue() + ", ");
}
}
示例3: Main
static void Main(string[] args)
{
List<int> list = new List<int>
{
3,2,
}; // 3, 2
list.Add(5); // 3, 2, 5
list.Add(6); // 3, 2, 5, 6
list.Remove(5); // 3, 2, 6
Queue<int> queue = new Queue<int>();
queue.Enqueue(3);// 3
queue.Enqueue(8);// 3, 8
queue.Dequeue(); // 8
Stack<int> stack = new Stack<int>();
stack.Push(2); // 2
stack.Push(7); // 7, 2
stack.Push(8); // 8, 7, 2
stack.Pop(); // 7, 2
foreach (var i in stack)
{
Console.WriteLine(i);
}
LinkedList<int> linkedList = new LinkedList<int>();
linkedList.AddFirst(9); // 9
linkedList.AddAfter(linkedList.Find(9), 5); // 9, 5
linkedList.Remove(9); // 5
Console.Read();
}
示例4: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether Peek() is successful when the queue is not empty.");
try
{
Queue<string> TestQueue = new Queue<string>();
TestQueue.Enqueue("one");
TestQueue.Enqueue("two");
TestQueue.Enqueue("three");
string PeekResult = TestQueue.Peek();
if (PeekResult != "one")
{
TestLibrary.TestFramework.LogError("P01.1", "Peek() failed! Expected value is "+"\"one\". But actual value is \""+PeekResult+"\".");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogVerbose(e.StackTrace);
retVal = false;
}
return retVal;
}
示例5: AddTriVertexCycle
private static void AddTriVertexCycle(List<int> list)
{
Queue<int> queue = new Queue<int>();
int minVertex = Int32.MaxValue;
for (var i = 0; i < 3; i++)
{
int vertex = list[list.Count - 3 + i];
if (vertex < minVertex)
{
minVertex = vertex;
}
queue.Enqueue(vertex);
}
while (minVertex != queue.Peek())
{
queue.Enqueue(queue.Dequeue());
}
string str = "{" + string.Join(" -> ", queue) + "}";
if (!uniqueCycles.Contains(str))
{
uniqueCycles.Add(str);
Console.WriteLine(str);
}
}
示例6: EnqueueRecursive
public static void EnqueueRecursive(AbstractProjectBrowserTreeNode node)
{
lock (queue) {
if (inQueue.Add(node))
queue.Enqueue(node);
// use breadth-first search
Queue<AbstractProjectBrowserTreeNode> q = new Queue<AbstractProjectBrowserTreeNode>();
q.Enqueue(node);
while (q.Count > 0) {
node = q.Dequeue();
foreach (TreeNode n in node.Nodes) {
node = n as AbstractProjectBrowserTreeNode;
if (node != null) {
q.Enqueue(node);
if (inQueue.Add(node))
queue.Enqueue(node);
}
}
}
if (!threadRunning) {
threadRunning = true;
ThreadPool.QueueUserWorkItem(Run);
}
}
}
示例7: BFS
static void BFS(IDictionary<int, Node> nodes, Node node)
{
var q = new Queue<Node>();
q.Enqueue(node);
while(q.Count > 0){
var n = q.Dequeue();
if (n.Processed)
continue;
foreach(var edge in n.Edges){
var nodeY = nodes[edge];
if (nodeY.Processed)
continue;
var distance = n.Distance + 6;
if (nodeY.Distance == -1 || (nodeY.Distance>0 && distance < nodeY.Distance)){
nodeY.Distance = distance;
}
q.Enqueue(nodeY);
}
n.Processed = true;
}
}
示例8: GrowByVertexArea
public static void GrowByVertexArea(TriMesh mesh)
{
Queue<TriMesh.Vertex> queue = new Queue<HalfEdgeMesh.Vertex>();
double[] avgArea = new double[mesh.Vertices.Count];
foreach (var v in mesh.Vertices)
{
avgArea[v.Index] = TriMeshUtil.ComputeAreaOneRing(v);
if (v.Traits.SelectedFlag != 0)
{
queue.Enqueue(v);
}
}
double k = 0.896;
while (queue.Count != 0)
{
TriMesh.Vertex center = queue.Dequeue();
foreach (var round in center.Vertices)
{
if (round.Traits.SelectedFlag == 0)
{
if (Math.Abs(avgArea[center.Index] -
avgArea[round.Index]) < k * avgArea[center.Index])
{
round.Traits.SelectedFlag = center.Traits.SelectedFlag;
queue.Enqueue(round);
}
}
}
}
}
示例9: TraverseBFS
public static void TraverseBFS(int node)
{
// Queue e obhojdane v shirnia(BSF algoritam), dokato ako e Stack ste e obhojdane v dalbochina(DFS algoritam)
var nodes = new Queue<int>();
var visited = new bool[childNodes.Length];
// Enqueue the start node to the queue
visited[node] = true;
nodes.Enqueue(node);
// Breadth-First Search (BFS)
while (nodes.Count != 0)
{
var currentNode = nodes.Dequeue();
Console.WriteLine("{0} ({1})", currentNode, nodeNames[currentNode]);
foreach (var childNode in childNodes[currentNode])
{
if (!visited[childNode])
{
nodes.Enqueue(childNode);
visited[childNode] = true;
}
}
}
}
示例10: Main
static void Main(string[] args)
{
Queue<String> fila = new Queue<String>();
//System.Collections.Queue -> de Objects
fila.Enqueue("zé");
fila.Enqueue("chico");
fila.Enqueue("tião");
fila.Enqueue("tonho");
foreach (var item in fila)
{
Console.WriteLine(item);
}
Console.WriteLine(fila.Peek());
Console.WriteLine(fila.Peek());
Console.WriteLine(fila.Peek());
while (fila.Count > 0)
Console.WriteLine(fila.Dequeue());
Console.WriteLine(fila.Count);
Console.ReadKey();
}
示例11: CalcSequence
private static List<int> CalcSequence(int N, int M)
{
List<int> result = new List<int>();
Node<int> root = new Node<int>(N);
BuildTree(root, M);
Queue<Node<int>> search = new Queue<Node<int>>();
search.Enqueue(root);
while (search.Count > 0)
{
Node<int> number = search.Dequeue();
if (number.Value == M)
{
while (number.HasParent)
{
result.Add(number.Value);
number = number.Parent;
}
result.Add(N);
break;
}
foreach (var child in number.Children)
{
search.Enqueue(child);
}
}
result.Reverse();
return result;
}
示例12: Update
// Update is called once per frame
void Update()
{
var destination = (Vector2)traker.Markers.First.Value.position;
var arrived = new Queue<Pikmin>();
var candidates = new LinkedList<Pikmin>();
foreach (var pik in pikmins.pikmins) {
var toDest = destination - (Vector2)pik.transform.position;
var hys = pik.state != Pikmin.State.Other ? + hysteresis : - hysteresis;
if (toDest.sqrMagnitude < arrivalDistance * arrivalDistance + hys) {
pik.state = Pikmin.State.Friend;
arrived.Enqueue(pik);
} else {
pik.state = Pikmin.State.Other;
candidates.AddLast(pik);
}
}
while (arrived.Count > 0) {
var pik = arrived.Dequeue();
var cand = candidates.First;
while (cand != null) {
var toArrived = (Vector2)pik.transform.position - (Vector2)cand.Value.transform.position;
var hys = cand.Value.state != Pikmin.State.Other ? + hysteresis : - hysteresis;
if (toArrived.sqrMagnitude < arrivalDistance * arrivalDistance + hys) {
arrived.Enqueue(cand.Value);
candidates.Remove(cand);
cand.Value.state = Pikmin.State.Relation;
}
cand = cand.Next;
}
}
}
示例13: RepresentativeTable
// Constructor for creating a new representative table. We directly fill the table depending on the given sequence.
public RepresentativeTable(Graph graph, Tree tree)
{
// Initialize the table
_table = new Dictionary<BitSet, RepresentativeList>();
Queue<BitSet> queue = new Queue<BitSet>();
queue.Enqueue(tree.Root);
_table[new BitSet(0, graph.Size)] = new RepresentativeList();
int i = 0;
while (queue.Count != 0)
{
BitSet node = queue.Dequeue();
FillTable(graph, node);
FillTable(graph, graph.Vertices - node);
if (tree.LeftChild.ContainsKey(node))
{
queue.Enqueue(tree.LeftChild[node]);
}
if (tree.RightChild.ContainsKey(node))
{
queue.Enqueue(tree.RightChild[node]);
}
}
}
示例14: FindChildByName
/// <summary>
/// Attempts to find a child DependencyObject by name.
/// </summary>
/// <param name="dependencyObject">DependencyObject to search.</param>
/// <param name="name">Name of the child element to find.</param>
/// <returns>A child DependencyObject with the provided name or null if not found.</returns>
internal static DependencyObject FindChildByName(this DependencyObject dependencyObject, string name)
{
Queue<DependencyObject> queue = new Queue<DependencyObject>();
// Enqueue starting point
queue.Enqueue(dependencyObject);
// Do a BFS search on children
while (queue.Count > 0)
{
DependencyObject node = queue.Dequeue();
// Check for a match
FrameworkElement frameworkElement = node as FrameworkElement;
if (frameworkElement != null)
{
if (frameworkElement.Name.Equals(name, StringComparison.Ordinal))
{
return frameworkElement;
}
}
// Add children
foreach (DependencyObject child in node.GetCurrentChildren())
{
queue.Enqueue(child);
}
}
return null;
}
示例15: Main
static void Main(string[] args)
{
const int DesiredCount = 50;
int N = int.Parse(Console.ReadLine());
Queue<int> numbersStorage = new Queue<int>();
Queue<int> baseNumberStorage = new Queue<int>();
baseNumberStorage.Enqueue(N);
int baseNumber;
int currentNumber;
for (int i = 0; i < DesiredCount; i += 3)
{
baseNumber = baseNumberStorage.Dequeue();
currentNumber = baseNumber + 1;
numbersStorage.Enqueue(currentNumber);
baseNumberStorage.Enqueue(currentNumber);
currentNumber = (baseNumber * 2) + 1;
numbersStorage.Enqueue(currentNumber);
baseNumberStorage.Enqueue(currentNumber);
currentNumber = baseNumber + 2;
numbersStorage.Enqueue(currentNumber);
baseNumberStorage.Enqueue(currentNumber);
}
Console.Write(N + " ");
for (int i = 0; i < DesiredCount; i++)
{
Console.Write("{0} ", numbersStorage.Dequeue());
}
}