本文整理汇总了C#中System.Collections.Queue.Enqueue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Enqueue方法的具体用法?C# Queue.Enqueue怎么用?C# Queue.Enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Enqueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getTypes
private static IEnumerable<Type> getTypes(Type sourceType)
{
Queue<Type> pending = new Queue<Type>();
HashSet<Type> visited = new HashSet<Type>();
pending.Enqueue(sourceType);
while (pending.Count != 0)
{
Type type = pending.Dequeue();
visited.Add(type);
yield return type;
if (type.BaseType != null)
{
if (!visited.Contains(type.BaseType))
{
pending.Enqueue(type.BaseType);
}
}
foreach (Type interfaceType in type.GetInterfaces())
{
if (!visited.Contains(interfaceType))
{
pending.Enqueue(interfaceType);
}
}
}
}
示例2: FillQueue
private static void FillQueue(int firstX, int firstY, byte currColor, byte destColor)
{
Queue<Tuple<int, int>> q = new Queue<Tuple<int, int>>();
q.Enqueue(Tuple.Create(firstX, firstY));
var maxX = _data.GetLength(0);
var maxY = _data.GetLength(1);
while (q.Count > 0)
{
var point = q.Dequeue();
var x = point.Item1;
var y = point.Item2;
if (_data[x, y] == destColor)
continue;
if (_data[x, y] != currColor)
continue;
_data[x, y] = destColor;
if (x + 1 < maxX)
q.Enqueue(Tuple.Create(x + 1, y));
if (x - 1 >= 0)
q.Enqueue(Tuple.Create(x - 1, y));
if (y + 1 < maxY)
q.Enqueue(Tuple.Create(x, y + 1));
if (y - 1 >= 0)
q.Enqueue(Tuple.Create(x, y - 1));
Display(_data);
}
}
示例3: getPath
public int[] getPath(DirectedGraph g, int vertex)
{
Queue<int> q = new Queue<int>();
q.Enqueue(vertex);
//set up the entire distance matrix with -1 except for the vertex node
for (int i = 0; i < g.getTotalVertices(); i++)
{
distanceMatrix[i] = -1;
}
//set up current vertex with 0 because there will be no distance
distanceMatrix[vertex] = 0;
while (q.Count > 0)
{
int v = q.Dequeue();
Console.Write(v); //this is the breadth first traversal
ArrayList adjacent = g.Adjacent(v);
//loop through all the adjacent nodes, if the currentVertex is still -1, then go in and do process
for (int i = 0; i < adjacent.Count; i++)
{
int currentVertex = (int)adjacent[i];
if (distanceMatrix[currentVertex] == -1)
{
//add one to the distanceMatrix here because it's going to be from v to the current path
distanceMatrix[currentVertex] = distanceMatrix[v] + 1;
pathMatrix[currentVertex] = v;
q.Enqueue(currentVertex);
}
}
}
return distanceMatrix;
}
示例4: GetActivity
private static Activity GetActivity(Activity containerActivity, string id)
{
if (containerActivity != null)
{
Queue queue = new Queue();
queue.Enqueue(containerActivity);
while (queue.Count > 0)
{
Activity activity = (Activity) queue.Dequeue();
if (activity.Enabled)
{
if (activity.QualifiedName == id)
{
return activity;
}
if (activity is CompositeActivity)
{
foreach (Activity activity2 in ((CompositeActivity) activity).Activities)
{
queue.Enqueue(activity2);
}
}
}
}
}
return null;
}
示例5: SimpleStartToEndScenarioTest
public void SimpleStartToEndScenarioTest()
{
// Setup Fakes
var fakeRtEvents = new FakeRTEvents();
var fakeDecalEvents = new FakeDecalEventsProxy();
Queue<Location> locationResults = new Queue<Location>();
locationResults.Enqueue(new Location(0, 0, 1, 0, 0));
locationResults.Enqueue(new Location(0, 0, 2, 0, 0));
locationResults.Enqueue(new Location(0, 0, 3, 0, 0));
locationResults.Enqueue(new Location(0, 0, 4, 0, 0));
for (int i = 0; i < JumpRecorder.NumberOfConsecutiveZCoordsSameToSingleLand; i++)
{
locationResults.Enqueue(new Location(0, 0, 5, 0, 0));
}
List<SelfJumpCompleteEventArgs> cachedCompleteCallValues = new List<SelfJumpCompleteEventArgs>();
// Workflow to Test
JumpRecorder recorder = new JumpRecorder(fakeRtEvents, fakeDecalEvents, e => cachedCompleteCallValues.Add(e), () => locationResults.Dequeue());
var initialJumpData = new JumpData(new Location(0, 0, 0, 0, 0), 0.0, 0.0);
Assert.IsFalse(recorder.IsRecording);
fakeRtEvents.FireSelfJump(new JumpEventArgs(0, initialJumpData, 0, 0));
Assert.IsTrue(recorder.IsRecording);
fakeDecalEvents.FireRenderFrame(new EventArgs());
fakeDecalEvents.FireRenderFrame(new EventArgs());
fakeDecalEvents.FireRenderFrame(new EventArgs());
// We should not have landed yet
Assert.IsTrue(recorder.IsRecording);
Assert.AreEqual(0, cachedCompleteCallValues.Count);
fakeDecalEvents.FireRenderFrame(new EventArgs());
for (int i = 0; i < JumpRecorder.NumberOfConsecutiveZCoordsSameToSingleLand; i++)
{
fakeDecalEvents.FireRenderFrame(new EventArgs());
}
// Now we should have landed
Assert.IsFalse(recorder.IsRecording);
Assert.AreEqual(1, cachedCompleteCallValues.Count);
Assert.AreEqual(initialJumpData, cachedCompleteCallValues[0].JumpData);
Assert.AreEqual(4 + JumpRecorder.NumberOfConsecutiveZCoordsSameToSingleLand, cachedCompleteCallValues[0].Trajectory);
Assert.AreEqual(1, cachedCompleteCallValues[0].Trajectory[0].Z);
Assert.AreEqual(5, cachedCompleteCallValues[0].Trajectory.Last().Z);
Assert.AreEqual(5, cachedCompleteCallValues[0].LandingLocation.Z);
}
示例6: CreateGraph
public static Dictionary<AbstractState, Node> CreateGraph(Node root, params AbstractAction[] actions)
{
Dictionary<AbstractState, Node> uniqeNodes = new Dictionary<AbstractState, Node>();
uniqeNodes.Add(root.State, root);
Queue<Node> queue = new Queue<Node>();
queue.Enqueue(root);
while (queue.Count > 0)
{
Node curNode = queue.Dequeue();
foreach (var action in actions)
{
AbstractState state = action.execute(curNode);
if (state != null)
if (!uniqeNodes.ContainsKey(state))
{
Node newNode = new Node(state);
curNode.Children.Add(new Tuple<Node, AbstractAction>(newNode, action));
uniqeNodes.Add(state, newNode);
queue.Enqueue(newNode);
}
else
{
curNode.Children.Add(new Tuple<Node, AbstractAction>(uniqeNodes[state], action));
}
}
}
return uniqeNodes;
}
示例7: LevelOrderBottom
public IList<IList<int>> LevelOrderBottom(TreeNode root)
{
IList<IList<int>> result = new List<IList<int>>();
if (root == null)
return result;
Stack<IList<int>> stack = new Stack<IList<int>>();
Queue<TreeNode> queue = new Queue<TreeNode>();
queue.Enqueue(root);
while (queue.Count > 0)
{
IList<int> items = new List<int>();
int num = queue.Count;
for (int i = 0; i < num; i++)
{
TreeNode node = queue.Dequeue();
items.Add(node.val);
if (node.left != null)
queue.Enqueue(node.left);
if (node.right != null)
queue.Enqueue(node.right);
}
stack.Push(items);
}
while (stack.Count > 0)
result.Add(stack.Pop());
return result;
}
示例8: Main
static void Main(string[] args)
{
//New Queue of Integers
Queue<int> queue = new Queue<int>();
queue.Enqueue(5);
queue.Enqueue(10);
queue.Enqueue(15);
queue.Enqueue(20);
/*Create new array with
length equal to Queue's element count*/
int[] array = new int[queue.Count];
//Copy the Queue to the Array
queue.CopyTo(array, 0);
//Loop through and display int[] in order
Console.WriteLine("Array: ");
for (int i=0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
//Loop through int array in reverse order
Console.WriteLine("Array reverse order: ");
for (int i = array.Length -1; i >= 0; i--)
{
Console.WriteLine(array[i]);
}
}
示例9: Main_7_9_6
//Main_7_9_6
public static void Main_7_9_6()
{
Queue myQueue = new Queue();
//��Queueβ�����Ԫ��
myQueue.Enqueue("��");
myQueue.Enqueue("��");
myQueue.Enqueue("˭");
//����Queueu��ʼ��Ԫ��
Console.WriteLine(myQueue.Peek());
//���ز��Ƴ�Queue��ʼ��Ԫ��
myQueue.Dequeue();
//����Queue
foreach (object o in myQueue)
Console.WriteLine(o.ToString());
Stack myStack = new Stack();
//��Stack��������Ԫ��
myStack.Push("��");
myStack.Push("��");
myStack.Push("˭");
//����Stack������Ԫ��
Console.WriteLine(myStack.Peek());
//���ز��Ƴ�Stack������Ԫ��
myStack.Pop();
//����Stack
foreach (object o in myStack)
Console.WriteLine(o.ToString());
}
示例10: printTreeByLevel
public void printTreeByLevel(Node root)
{
if (root==null) return;
Queue cur = new Queue();
Queue next = new Queue();
cur.Enqueue(root);
while ((cur.Count > 0) || (next.Count > 0))
{
if (cur.Count > 0)
{
Node temp = (Node)cur.Dequeue();
Console.Write("{0}->", temp.value);
if (temp.right != null)
next.Enqueue(temp.right);
if (temp.left != null)
next.Enqueue(temp.left);
}
else
{
Console.WriteLine();
Queue tq = next;
next = cur;
cur = tq;
}
}
}
示例11: calculateSum
public int calculateSum()
{
InOrder id = new InOrder();
Node root = id.createTree(2);
Queue myQueue = new Queue();
myQueue.Enqueue(root);
int sum = 0;
while (myQueue.Count > 0)
{
Node top = (Node)myQueue.Dequeue();
if ((top.left == null) && (top.right == null))
{
sum += top.value;
}
if (top.left != null)
{
top.left.value = top.value * 10 + top.left.value;
myQueue.Enqueue(top.left);
}
if (top.right != null)
{
top.right.value = top.value * 10 + top.right.value;
myQueue.Enqueue(top.right);
}
}
return sum;
}
示例12: GetRenderersWithoutInstancesInChildren
private Renderer[] GetRenderersWithoutInstancesInChildren() {
List<Renderer> renderers = new List<Renderer>();
Queue<Transform> transformQueue = new Queue<Transform>();
// enqueue children first
foreach (Transform child in transform) {
transformQueue.Enqueue(child);
}
while (transformQueue.Count > 0) {
Transform t = transformQueue.Dequeue();
GameObject g = t.gameObject;
RendererInstance instance = g.GetComponent<RendererInstance>();
if (instance == null) {
Renderer r = g.GetComponent<Renderer>();
if (r != null) {
renderers.Add(r);
}
foreach (Transform child in t) {
transformQueue.Enqueue(child);
}
}
}
return renderers.ToArray();
}
示例13: Mai
static void Mai(string[] args)
{
//Cola.
Queue q = new Queue();
q.Enqueue("A");
q.Enqueue(new Persona());
Console.WriteLine(q.Dequeue());
Console.WriteLine(q.Dequeue());
//Es lo mas parecido a un array dinamico
ArrayList p = new ArrayList();
p.Add(new Persona());
p.Add(new Persona());
p.Add("Pepe");
p.Add(new Persona());
p.Add(new Persona());
p.Add("");
p.Add(new Persona());
Console.WriteLine(p[2]);
Console.ReadLine();
//Diccionario. Estructura de datos que se almacena con claves.
//Para usarlo llamaremos directamente a la clave.
}
示例14: createPoints
/// <summary>
/// Creates the points.
/// </summary>
/// <returns>GestChecker wtih points</returns>
public GameObject createPoints()
{
//int count = transform.childCount;
Queue<Transform> fronta = new Queue<Transform>();
//Queue<Transform> fronta2 = new Queue<Transform>();
fronta.Enqueue(transform);
GameObject checkerClone = (GameObject) GameObject.Instantiate(checker,transform.position,Quaternion.identity);
GameObject fig = figureCopy();
//fronta2.Enqueue(fig.transform.GetChild(0));
fig.transform.parent = checkerClone.transform;
while(fronta.Count>0)
{
Transform last = fronta.Dequeue();
//Transform last2 = fronta2.Dequeue();
int num = last.childCount;
for(int i=0; i<num;i++)
{
fronta.Enqueue(last.GetChild(i));
//fronta2.Enqueue(last2.GetChild(i));
}
GameObject clone = (GameObject) GameObject.Instantiate(checke,last.position,Quaternion.identity);
clone.name = last.name+"-check";
clone.transform.parent = checkerClone.transform;
// last2.transform.position = last.transform.position;
//last2.transform.rotation = last.transform.rotation;
}
return checkerClone;
}
示例15: Mai
static void Mai(string[] args)
{
//4 algoritmos para almacenar informacion.
//1.Colas (FIFO)
//2.Pilas (LIFO)
//3.Listas (Array dinamico, se accede a su informacion por el indice)
//4.Diccionarios ()
//5.Set()
//Cola
Queue q=new Queue();
q.Enqueue("A");
q.Enqueue(new Persona());//Enqueue para meter datos
Console.WriteLine(q.Dequeue());//El dequeue para sacar datos
Console.WriteLine(q.Dequeue());
ArrayList l=new ArrayList();
l.Add(new Persona());
l.Add(new Persona());
l.Add(new Persona());
l.Add(new Persona());
l.Add("Pepo");
l.Add(23);
l.Add(new Persona());
l.Add(new Persona());
Console.WriteLine(l[4]);
Console.ReadLine();
}