当前位置: 首页>>代码示例>>C#>>正文


C# Queue.Count方法代码示例

本文整理汇总了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;
        }
开发者ID:FrankHYB,项目名称:MarioGame,代码行数:29,代码来源:FireballCollision.cs

示例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;
        }
开发者ID:husthk986,项目名称:BlackSwan,代码行数:29,代码来源:_7ReverseInteger.cs

示例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);
		}
开发者ID:mmooney,项目名称:MMDB.DataService,代码行数:32,代码来源:X12Verifier.cs

示例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;
            }
        }
开发者ID:CensoredHF,项目名称:Snappie,代码行数:28,代码来源:Tiler.cs

示例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;
                        }
                    }
                }
            }
        }
开发者ID:SurgicalSteel,项目名称:AlgorithmSimulation,代码行数:33,代码来源:Program.cs

示例6: QueueCount

 public void QueueCount()
 {
     var queue = new Queue<int>();
     queue.Enqueue(2);
     queue.Enqueue(3);
     Assert.AreEqual(2, queue.Count());
 }
开发者ID:anton-christensen,项目名称:p2_software,代码行数:7,代码来源:QueueStackandCloneTests.cs

示例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;
        }
开发者ID:avineshwar,项目名称:Scheduling-Simulator,代码行数:39,代码来源:Scheduling.cs

示例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);
            }
            */
        }
开发者ID:SurgicalSteel,项目名称:AlgorithmSimulation,代码行数:34,代码来源:Program.cs

示例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);

            }
        }
开发者ID:FrankHYB,项目名称:MarioGame,代码行数:59,代码来源:LuigiItemCollision.cs

示例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);
        }
开发者ID:FrankHYB,项目名称:MarioGame,代码行数:59,代码来源:LuigiEnemyCollision.cs

示例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();
        }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:53,代码来源:Solution301.cs

示例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;
        }
开发者ID:cswanson0,项目名称:War-Card-Game,代码行数:24,代码来源:Battle.cs

示例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);
         }
     }
 }
开发者ID:johannes-qvarford,项目名称:LunchLadySimulator,代码行数:16,代码来源:HierarchyExtensions.cs

示例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;
        }
开发者ID:husthk986,项目名称:BlackSwan,代码行数:46,代码来源:_8StringToInteger.cs

示例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();
 }
开发者ID:walrus7521,项目名称:code,代码行数:18,代码来源:twentythree.cs


注:本文中的Queue.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。