本文整理汇总了C#中Queue.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Count方法的具体用法?C# Queue.Count怎么用?C# Queue.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FireballEnemyCollisionTest
// when a ball hits an enemy both are destroyed
public bool FireballEnemyCollisionTest(IList<IEnemy> enemies)
{
Rectangle fbRectangle = fireball.GetRectangle();
Rectangle enemyRectangle;
Rectangle intersectionRectangle;
Queue<IEnemy> doomedEnemies = new Queue<IEnemy>();
foreach (IEnemy enemy in enemies)
{
enemyRectangle = enemy.GetRectangle();
intersectionRectangle = Rectangle.Intersect(fbRectangle, enemyRectangle);
if (!intersectionRectangle.IsEmpty)
{
// hud score method needed
doomedEnemies.Enqueue(enemy);
}
}
while (doomedEnemies.Count() > 0)
{
IEnemy e = doomedEnemies.Dequeue();
enemies.Remove(e);
return true;
}
return false;
}
示例2: Reverse
public int Reverse(int x)
{
if (x < 0 && 0 - x < 0)
return 0;
Queue<int> iStack = new Queue<int>();
bool minus = x < 0;
x = minus ? 0 - x : x;
while (x > 0)
{
iStack.Enqueue(x % 10);
x = x / 10;
}
int result = 0;
while (iStack.Count() > 0)
{
if (result > int.MaxValue / 10)
return 0;
result = result * 10 + iStack.Dequeue();
}
if (minus)
return 0 - result;
return result;
}
示例3: VerifyLine
public void VerifyLine(string expectedData, string actualData, string segmentID, IEnumerable<string> preceedingTags = null, int expectedOccurance = 0, char fieldSeperator='*')
{
Assert.IsNotNullOrEmpty(actualData);
string[] arrLines = actualData.Split(this.LineSeperators, StringSplitOptions.RemoveEmptyEntries);
Queue<string> preceedingQueue = new Queue<string>(preceedingTags ?? new string[] {});
int actualOccurances = 0;
foreach(string line in arrLines)
{
if(preceedingQueue.Count > 0)
{
string nextExpectedTag = preceedingQueue.Peek();
if(line.StartsWith(nextExpectedTag + fieldSeperator))
{
preceedingQueue.Dequeue();
}
}
if (line.StartsWith(segmentID + fieldSeperator))
{
if(expectedOccurance == actualOccurances)
{
Assert.AreEqual(expectedData, line);
Assert.IsEmpty(preceedingQueue, "Previous tag not found: {0}",(preceedingQueue.Count()>0)?preceedingQueue.Peek():string.Empty);
return;
}
else
{
actualOccurances++;
}
}
}
Assert.Fail("Did not find segment " + segmentID);
}
示例4: Tile
public static void Tile(IEnumerable<DragablzItem> dragablzItems, Size bounds)
{
if (dragablzItems == null) throw new ArgumentNullException("dragablzItems");
var items = new Queue<DragablzItem>(dragablzItems.OrderBy(Panel.GetZIndex));
var cellCountPerColumn = TilerCalculator.GetCellCountPerColumn(items.Count());
var x = 0d;
var cellWidth = bounds.Width / cellCountPerColumn.Length;
foreach (var cellCount in cellCountPerColumn)
{
var y = 0d;
var cellHeight = bounds.Height / cellCount;
for (var cell = 0; cell < cellCount; cell++)
{
var item = items.Dequeue();
Layout.SetFloatingItemState(item, WindowState.Normal);
item.SetCurrentValue(DragablzItem.XProperty, x);
item.SetCurrentValue(DragablzItem.YProperty, y);
item.SetCurrentValue(FrameworkElement.WidthProperty, cellWidth);
item.SetCurrentValue(FrameworkElement.HeightProperty, cellHeight);
y += cellHeight;
}
x += cellWidth;
}
}
示例5: BFS
static void BFS(FakeGraph fg, string kotaasal, string kotadicari)
{
ParentNode v = fg.pn[fg.findindex(kotaasal)];
List<ParentNode> discovered = new List<ParentNode>();
Queue<ParentNode> antrian = new Queue<ParentNode>();
antrian.Enqueue(v);
discovered.Add(v);
while (!antrian.Count.Equals(0))
{
v = antrian.Dequeue();
Queue<ParentNode> tetanggaku = new Queue<ParentNode>();
tetanggaku = fg.tetangganyadarikota(v);
for (int i = 0; i < tetanggaku.Count(); i++)
{
if (!sudahdiscoverkah(discovered, tetanggaku.ElementAt(i)))
{
antrian.Enqueue(tetanggaku.ElementAt(i));
discovered.Add(tetanggaku.ElementAt(i));
if (tetanggaku.ElementAt(i).Equals(fg.pn[fg.findindex(kotadicari)]))
{
Console.WriteLine("Kota Ditemukan!");
Console.WriteLine("Jalur Penelusuran :");
for (int y = 0; y < discovered.Count(); y++)
{
Console.WriteLine(discovered.ElementAt(y).nama);
}
break;
}
}
}
}
}
示例6: QueueCount
public void QueueCount()
{
var queue = new Queue<int>();
queue.Enqueue(2);
queue.Enqueue(3);
Assert.AreEqual(2, queue.Count());
}
示例7: ExecuteFCFS
/// <summary>
/// To Execute First-Come First-Serve algorithm
/// </summary>
/// <returns>return job processed stored in a queue</returns>
public Queue<Job> ExecuteFCFS()
{
Queue<Job> jobQueue = new Queue<Job>();
Queue<Job> jobDoneQueue = new Queue<Job>();
jobQueue = GetData(fileName);
int jobExecution = 0;
int time = 0;
while (jobQueue.Count() != 0)
{
Job job = jobQueue.Dequeue();
jobExecution = job.executionTime;
time += jobExecution;
job.processedTime = jobExecution;
job.turnaroundTime += jobExecution;
job.executionTime -= jobExecution;
jobDoneQueue.Enqueue(job);
foreach (Job jobElement in jobQueue)
{
if (jobElement.arrivalTime <= time)
{
jobElement.waitTime = time - jobElement.arrivalTime;
jobElement.turnaroundTime = time - jobElement.arrivalTime;
}
}
}
PrintResult(jobDoneQueue, "FCFS");
return jobDoneQueue;
}
示例8: BFSTraversal
static void BFSTraversal(FakeGraph fg, string kotaasal)
{
ParentNode v = fg.pn[fg.findindex(kotaasal)];
List<ParentNode> discovered = new List<ParentNode>();
Queue<ParentNode> antrian = new Queue<ParentNode>();
antrian.Enqueue(v);
discovered.Add(v);
while (!antrian.Count.Equals(0))
{
v = antrian.Dequeue();
Queue<ParentNode> tetanggaku = new Queue<ParentNode>();
tetanggaku = fg.tetangganyadarikota(v);
for (int i = 0; i < tetanggaku.Count(); i++)
{
if(!sudahdiscoverkah(discovered,tetanggaku.ElementAt(i)))
{
antrian.Enqueue(tetanggaku.ElementAt(i));
discovered.Add(tetanggaku.ElementAt(i));
}
}
}
Console.WriteLine();
for (int i = 0; i < discovered.Count(); i++)
{
Console.WriteLine(discovered.ElementAt(i).nama);
}
/*
foreach (ParentNode p in discovered)
{
Console.WriteLine(p.nama);
}
*/
}
示例9: ItemCollisionTest
public void ItemCollisionTest(SoundEffects sound, HUD hud, IList<IItem> items)
{
Rectangle luigiRectangle = myLuigi.GetRectangle();
Rectangle itemRectangle;
Rectangle intersectionRectangle;
Queue<IItem> doomedItems = new Queue<IItem>();
foreach (IItem item in items)
{
itemRectangle = item.GetRectangle();
intersectionRectangle = Rectangle.Intersect(luigiRectangle, itemRectangle);
if (!intersectionRectangle.IsEmpty)
{
// todo
switch (item.GetItemName())
{
case "Coin":
//myLuigi.Coin();
hud.addCoinLuigi();
hud.increaseScoreLuigi(Constants.coinValue);
hud.achievements.CoinGet();
break;
case "Mushroom":
sound.Powerup();
myLuigi.Mushroom();
hud.increaseScoreLuigi(Constants.mushroomValue);
hud.achievements.MushroomGet();
break;
case "Fireflower":
sound.Powerup();
myLuigi.Fireflower();
hud.increaseScoreLuigi(Constants.fireflowerValue);
hud.achievements.FlowerGet();
break;
case "Oneup":
sound.OneUp();
hud.extraLifeLuigi();
hud.increaseScoreLuigi(Constants.oneUpValue);
break;
case "Star":
sound.Powerup();
myLuigi.Star();
hud.increaseScoreLuigi(Constants.starValue);
hud.achievements.StarGet();
break;
default:
// nothing
break;
}
doomedItems.Enqueue(item);
}
}
while (doomedItems.Count() > 0)
{
IItem item = doomedItems.Dequeue();
items.Remove(item);
}
}
示例10: EnemyCollisionTest
public Tuple<int, bool> EnemyCollisionTest(Luigi luigi, HUD hud, IList<IEnemy> enemies, int x, SoundEffects sound)
{
Rectangle luigiRectangle = myLuigi.GetRectangle();
Rectangle enemyRectangle;
bool enemyKilled = false;
bool invincible = myLuigi.Invincible();
int xpos = x;
Rectangle intersectionRectangle;
Queue<IEnemy> doomedEnemies = new Queue<IEnemy>();
foreach (IEnemy enemy in enemies)
{
enemyRectangle = enemy.GetRectangle();
intersectionRectangle = Rectangle.Intersect(luigiRectangle, enemyRectangle);
if (!intersectionRectangle.IsEmpty)
{
if (intersectionRectangle.Width >= intersectionRectangle.Height)
{
sound.Bump();
doomedEnemies.Enqueue(enemy);
hud.luigiEnemyKill(luigi);
enemyKilled = true;
}
else if (invincible)
{
doomedEnemies.Enqueue(enemy);
}
else
{
myLuigi.Hit();
if (luigiRectangle.X < enemyRectangle.X)
{
xpos = xpos - intersectionRectangle.Width;
}
else
{
xpos = xpos + intersectionRectangle.Width;
}
if (myLuigi.IsDead())
{
hud.lifeLostLuigi();
}
}
}
}
while (doomedEnemies.Count() > 0)
{
IEnemy enemie = doomedEnemies.Dequeue();
enemies.Remove(enemie);
}
return new Tuple<int,bool>(xpos, enemyKilled);
}
示例11: RemoveInvalidParentheses
public IList<string> RemoveInvalidParentheses(string s)
{
HashSet<string> visit = new HashSet<string>();
List<string> re = new List<string>();
if (s.Length == 0)
{
re.Add(s);
return re;
}
Queue<string> st = new Queue<string>();
st.Enqueue(s);
bool found = false;
while(st.Count() > 0)
{
var curstr = st.Dequeue();
if (IsValid(curstr))
{
re.Add(curstr);
found = true;
}
if (found)
continue;
int len = curstr.Length;
for(int i=0; i<len; i++)
{
if (curstr[i] != '(' && curstr[i] != ')')
continue;
string substring;
if (i == 0)
substring = curstr.Substring(1);
else if (i == curstr.Length)
substring = curstr.Substring(0, len - 1);
else
substring = curstr.Substring(0, i) + curstr.Substring(i + 1, len - i - 1);
if (!visit.Contains(substring))
{
st.Enqueue(substring);
visit.Add(substring);
}
}
}
return re.ToList();
}
示例12: EvaluateWinner
private string EvaluateWinner(Player player1, PlayingCard p1Card, Player player2, PlayingCard p2Card,
Queue<PlayingCard> pot)
{
string winnerName = "";
if (p1Card.Value == p2Card.Value)
{
_result.Append("<strong>*******This is War!*******</strong>");
War(player1, player2, pot);
}
else if (p1Card.Value < p2Card.Value)
{
winnerName = String.Format("<span style='color:blue'>{0} wins pot of {1} cards!</span>",
player2.Name, pot.Count());
Winner(player2);
}
else
{
winnerName = String.Format("<span style='color:blue'>{0} wins pot of {1} cards!</span>",
player1.Name, pot.Count());
Winner(player1);
}
return winnerName;
}
示例13: AllChildren
public static IEnumerable<Transform> AllChildren(this ConvertedGameObject cg)
{
Transform t = cg.OwnerGameObject.transform;
Queue<Transform> parents = new Queue<Transform>();
parents.Enqueue(t);
while(parents.Count() != 0)
{
Transform queueChild = parents.Dequeue();
for(int i = 0; i < queueChild.childCount; ++i)
{
Transform child = queueChild.GetChild(i);
yield return child;
parents.Enqueue(child);
}
}
}
示例14: MyAtoi
public int MyAtoi(string str)
{
if (string.IsNullOrEmpty(str))
return 0;
str = str.Trim();
Queue<int> iStack = new Queue<int>();
bool minus = str[0] == '-';
int i = minus || str[0] == '+' ? 1 : 0;
if (minus && str.Length == 1)
{
return 0;
}
for (; i < str.Length; i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
iStack.Enqueue(str[i]);
}
else
{
return 0;
}
}
int result = 0;
while (iStack.Count() > 0)
{
int currentNumber = iStack.Dequeue() - '0';
if (result > int.MaxValue/10 || int.MaxValue - result*10 < currentNumber)
{
return minus ? int.MinValue : int.MaxValue;
}
result = result * 10 + currentNumber;
}
if (minus)
return 0 - result;
return result;
}
示例15: levelOrder
static void levelOrder(Node root)
{
//Write your code here
var queue = new Queue<Node>();
queue.Enqueue(root);
while (queue.Count() != 0) {
Node node = queue.Dequeue();
Console.Write(node.data);
Console.Write(' ');
if (node.left != null) {
queue.Enqueue(node.left);
}
if (node.right != null) {
queue.Enqueue(node.right);
}
}
Console.WriteLine();
}