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


C# Queue.Contains方法代码示例

本文整理汇总了C#中Queue.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Contains方法的具体用法?C# Queue.Contains怎么用?C# Queue.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether Contains() is successful.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");

            if (!TestQueue.Contains("one") || !TestQueue.Contains("two") || TestQueue.Contains("three"))
            {
                TestLibrary.TestFramework.LogError("P01.1", "Contains() failed!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:26,代码来源:queuecontains.cs

示例2: ContainsUsesEqualsMethod

		public void ContainsUsesEqualsMethod() {
			var q = new Queue<C>();
			q.Enqueue(new C(1));
			q.Enqueue(new C(2));
			q.Enqueue(new C(3));
			Assert.IsTrue(q.Contains(new C(2)));
			Assert.IsFalse(q.Contains(new C(4)));
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:8,代码来源:QueueTests.cs

示例3: ContainsWorks

		public void ContainsWorks() {
			var q = new Queue<int>();
			q.Enqueue(10);
			q.Enqueue(2);
			q.Enqueue(4);
			Assert.IsTrue(q.Contains(10));
			Assert.IsTrue(q.Contains(2));
			Assert.IsFalse(q.Contains(11));
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:9,代码来源:QueueTests.cs

示例4: TestContains

        public void TestContains()
        {
            var q = new Queue<int>();
            q.Enqueue(0);
            Assert.AreEqual(1, q.Count);

            Assert.IsTrue(q.Contains(0));
            Assert.IsFalse(q.Contains(1));
        }
开发者ID:Bpoe,项目名称:Data-Structures-and-Algorithms,代码行数:9,代码来源:QueueTests.cs

示例5: operate

 public int[] operate(int[] A, int[] B, string operation)
 {
     List<int> list = new List<int>();
     List<int> list2 = new List<int>();
     Queue<int> queue = new Queue<int>();
     switch (operation)
     {
         case "UNION":
             for (int i = 0; i < A.Length; i++)
                 list.Add(A[i]);
             for (int i = 0; i < B.Length; i++)
             {
                 if (!(list.Contains(B[i])))
                     list.Add(B[i]);
             }
             break;
         case "INTERSECTION":
             for (int i = 0; i < A.Length; i++)
                 queue.Enqueue(A[i]);
             for (int i = 0; i < B.Length; i++)
                 queue.Enqueue(B[i]);
             while (queue.Count > 0)
             {
                 int temp = queue.Dequeue();
                 if (queue.Contains(temp) && !(list.Contains(temp)) && !(list2.Contains(temp)))
                     list.Add(temp);
                 else
                     list2.Add(temp);
             }
             break;
         case "SYMMETRIC DIFFERENCE":
             for (int i = 0; i < A.Length; i++)
                 queue.Enqueue(A[i]);
             for (int i = 0; i < B.Length; i++)
                 queue.Enqueue(B[i]);
             while (queue.Count > 0)
             {
                 int temp = queue.Dequeue();
                 if (!queue.Contains(temp) && !(list.Contains(temp)) && !(list2.Contains(temp)))
                     list.Add(temp);
                 else
                     list2.Add(temp);
             }
             break;
     }
     int[] result = list.ToArray();
     Array.Sort(result);
     return result;
 }
开发者ID:Oscarbralo,项目名称:TopBlogCoder,代码行数:49,代码来源:Program.cs

示例6: DisableThemeFeatures

        public void DisableThemeFeatures(string themeName) {
            var themes = new Queue<string>();
            while (themeName != null) {
                if (themes.Contains(themeName))
                    throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
                var theme = _extensionManager.GetExtension(themeName);
                if (theme == null)
                    break;
                themes.Enqueue(themeName);

                themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
                    ? theme.BaseTheme
                    : null;
            }

            var currentTheme = _siteThemeService.GetCurrentThemeName();

            while (themes.Count > 0) {
                var themeId = themes.Dequeue();

                // Not disabling base theme if it's the current theme.
                if (themeId != currentTheme) {
                    _featureManager.DisableFeatures(new[] { themeId });
                }
            }
        }
开发者ID:Higea,项目名称:Orchard,代码行数:26,代码来源:ThemeService.cs

示例7: FindShortestSequenceOfOperations

        private static void FindShortestSequenceOfOperations(int n, int m, Queue<Func<int, int>> operations, Queue<int> sequence)
        {
            if (operations.Count < 1) { return; }

            var ops = new Queue<Func<int, int>>(operations);
            if (!sequence.Contains(n)) { sequence.Enqueue(n); }
            int result = ops.Dequeue()(n);
            if (result <= m) { sequence.Enqueue(result); }

            if (result == m)
            {
                int depth = sequence.Count - 1;
                while (sequence.Count > 0) { Console.Write(sequence.Dequeue() + " --> "); }
                Console.Write(depth + " operations");
                Console.WriteLine();
                return;
            }

            if (result > m * 2) { return; }

            if (result > m)
            {
                result = n;
            }

            FindShortestSequenceOfOperations(result, m, ops, sequence);
        }
开发者ID:Boyan1912,项目名称:Data-Structures-And-Algorithms,代码行数:27,代码来源:Program.cs

示例8: GetTiles

	// Get a list of all the tiles that are connected using BFS
	public List<Tile> GetTiles(Tile root)
	{
		List<Tile> tileList = new List<Tile>();
		
		Queue<Tile> q = new Queue<Tile>();
		
		q.Enqueue(root);
		
		while (q.Count > 0)
		{
			// pop the first item in the queue
			Tile current = q.Dequeue();
			tileList.Add(current);
			
			// if nothing pops, then all tiles have been found
			if (current == null)
				continue;
			
			// loop through all of root's neighbouring tiles 
			foreach (Transform tile in current.Neighbours)
			{
				_color = root.GetComponent<Renderer>().material.color;
				Color tileColor = tile.GetComponent<Renderer>().material.color;
				
				// get the tile component from the transform
				Tile t = tile.GetComponent<Tile>();
				
				// if the two colours match, then the tile is a neighbour
				// Enqueue the tile if it is not found in _tiles and in q
				if (_color == tileColor && !(tileList.Contains(t)) && !(q.Contains(t)))
					q.Enqueue(t);
			}
		}
		return tileList;
	}
开发者ID:EmilioF,项目名称:UnityProjects,代码行数:36,代码来源:MergeVillages.cs

示例9: Compressor

        public Compressor(int bigDelta, int a, int eps, int dmax, Domain[,] domains, FractalCompression.Structure.Region[,] regions, List<MappedPoint> interpolationPoints, Bitmap bitmap)
        {
            this.bigDelta = bigDelta;
            this.a = a;
            this.smallDelta = bigDelta / a;
            this.eps = eps;
            this.dmax = dmax;

            this.regions = regions;
            this.domains = domains;

            squeue = new Queue<FractalCompression.Structure.Region>();
            foreach (FractalCompression.Structure.Region r in regions)
                squeue.Enqueue(r);

            iqueue = new Queue<MappedPoint>();
            foreach (MappedPoint mp in interpolationPoints)
                if (!iqueue.Contains(mp))
                    iqueue.Enqueue(mp);

            aqueue = new Queue<int>();
            cqueue = new Queue<double>();
            squeue2 = new Queue<FractalCompression.Structure.Region>();

            d = 1;
            this.bitmap = bitmap;

            this.h = new double[regions.Length, domains.Length];
            this.minHQueue = new List<double>();
        }
开发者ID:BackupTheBerlios,项目名称:fractcomp,代码行数:30,代码来源:Compressor.cs

示例10: Main

    static void Main(string[] args)
    {
        Queue<int> queue = new Queue<int>();
        int[] commandArgs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        int add = commandArgs[0];
        int remove = commandArgs[1];
        int find = commandArgs[2];

        // Fill queue
        int[] queueInput = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        for (int i = 0; i < add; i++)
        {
            queue.Enqueue(queueInput[i]);
        }

        // Remove Dequeue
        for (int i = 0; i < remove; i++)
        {
            queue.Dequeue();
        }

        // Output
        if (queue.Contains(find))
        {
            Console.WriteLine("true");
        }
        else
        {
            Console.WriteLine(queue.Count > 0 ? queue.Min() : 0);
        }
    }
开发者ID:eMagicMan,项目名称:Study-CSharp,代码行数:32,代码来源:BasicQueueOperations.cs

示例11: Main

        private static void Main(string[] args)
        {
            Console.Write("N=");
            int n = int.Parse(Console.ReadLine());
            Console.Write("M=");
            int m = int.Parse(Console.ReadLine());

            var members = new Queue<int>();
            var visited = new HashSet<int>();

            int operationsCount = 0;
            long current = n;
            members.Enqueue(n);

            while (!members.Contains(m))
            {
                var tempQueue = new Queue<int>();
                for (int i = members.Count-1; i >= 0; i--)
                { 
                    var item = members.Dequeue();
                    if (!visited.Contains(item) && item<m)
                    {
                        tempQueue.Enqueue(item + 1);
                        tempQueue.Enqueue(item + 2);
                        tempQueue.Enqueue(item * 2);
                        visited.Add(item);
                    }
                    
                }
                operationsCount++;
                members = tempQueue;
            }
            Console.WriteLine(operationsCount);
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:34,代码来源:Program.cs

示例12: getTilesWithDistance

    public static List<Tile> getTilesWithDistance(Tile originTile, int distance)
    {
        if (distance == 0)
            return new List<Tile>();

        HashSet<Tile> closedSet = new HashSet<Tile>();
        Queue<Tile> openSet = new Queue<Tile>();
        List<Tile> result = new List<Tile>();

        foreach (Tile neighbour in originTile.Neighbours)
                openSet.Enqueue(neighbour);
        closedSet.Add(originTile);

        while(openSet.Count > 0)
        {
            Tile tileToCheck = openSet.Dequeue();
            var path = PathFinder.FindPath(originTile, tileToCheck);
            closedSet.Add(tileToCheck);
            if (path.ToList().Count - 1 <= distance)
            {
                result.Add(tileToCheck);
                    
                foreach (Tile tile in tileToCheck.Neighbours)
                    if (!closedSet.Contains(tile) && !openSet.Contains(tile))
                        openSet.Enqueue(tile);
            }
        }

        return result;
    }
开发者ID:VicBoss,项目名称:KR,代码行数:30,代码来源:GridHelper.cs

示例13: CreateRandomState

        public static EightPuzzleState CreateRandomState()
        {
            var result = new int[3, 3];

            var randomizedNumbers = new Queue<int>(9);
            for (int i = 0; i <= 8; i++)
            {
                int rnd;
                do
                {
                    rnd = _random.Next(0, 9);
                }
                while (randomizedNumbers.Contains(rnd));

                randomizedNumbers.Enqueue(rnd);
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    result[i, j] = randomizedNumbers.Dequeue();
                }
            }

            return new EightPuzzleState(result);
        }
开发者ID:MadCowDevelopment,项目名称:AIMA,代码行数:27,代码来源:EightPuzzleState.cs

示例14: Main

        static void Main()
        {
            Queue<string> INPUT = new Queue<string>();
            while (!INPUT.Contains("END"))
            {
                INPUT.Enqueue(Console.ReadLine().ToUpper());
            }

            BigInteger resultFirstTen  = 1;
            BigInteger resultOthers = 1;

            int counter = 0; //first 10 elements or less
            while(INPUT.Count > 1)
            {
                if (counter % 2 == 0)
                {
                    foreach (char digit in INPUT.Dequeue().ToString())
                    {
                        resultFirstTen *= (digit - '0');
                    }
                }
                else
                {
                    INPUT.Dequeue();
                }

                counter++;
                if (counter==10) { break; }
            }

            while(INPUT.Count>1)
            {
                if (counter % 2 == 0)
                {
                    foreach (char digit in INPUT.Dequeue().ToString())
                    {
                        resultOthers *= (digit - '0');
                    }
                }
                else
                {
                    INPUT.Dequeue();
                }

                counter++;
            }

            if ( counter <=10)
            {
                Console.WriteLine(resultFirstTen.ToString());
            }
            else
            {
                Console.WriteLine(resultFirstTen.ToString());
                Console.WriteLine(resultOthers.ToString());
            }
        }
开发者ID:tvmarinov,项目名称:Homework,代码行数:57,代码来源:ConsoleApp2.cs

示例15: Solve

        private void Solve(TextReader reader)
        {
            while (true) {
                var whs = reader.ReadLine().Split(' ').Select(s => int.Parse(s.Trim())).ToList();
                var width = whs[0];
                var height = whs[1];
                if (width == 0 && height == 0) {
                    return;
                }

                var map = new List<string>();
                for (int i = 0; i < height * 2 - 1; i++) {
                    var text = reader.ReadLine();
                    if (text.StartsWith(" ") && !text.EndsWith(" ")) {
                        text += " ";
                    }
                    map.Add(text);
                }

                var count = 0;
                var que = new Queue<Tuple<int, int>>();
                var newQue = new Queue<Tuple<int, int>>();
                var walked = new HashSet<Tuple<int, int>>();
                que.Enqueue(Tuple.Create(0, 0));
                while (!que.Contains(Tuple.Create(2 * width - 2, 2 * height - 2)) && que.Count > 0) {
                    newQue.Clear();

                    while (que.Count > 0) {
                        var p = que.Dequeue();
                        var x = p.Item1;
                        var y = p.Item2;

                        foreach (var dxy in dxys) {
                            if (!walked.Contains(Tuple.Create(x + dxy.Item1 * 2,
                                    y + dxy.Item2 * 2))) {
                                if (CanMove(map, x + dxy.Item1, y + dxy.Item2, x + dxy.Item1 * 2,
                                        y + dxy.Item2 * 2)) {
                                    newQue.Enqueue(Tuple.Create(x + dxy.Item1 * 2, y + dxy.Item2 * 2));
                                    walked.Add(Tuple.Create(x + dxy.Item1 * 2, y + dxy.Item2 * 2));
                                }
                            }
                        }
                    }

                    var tmpQue = que;
                    que = newQue;
                    newQue = tmpQue;
                    count++;
                }

                if (que.Count == 0) {
                    Console.WriteLine(0);
                } else {
                    Console.WriteLine(count + 1);
                }
            }
        }
开发者ID:exKAZUu,项目名称:ProgrammingContests,代码行数:57,代码来源:ProblemC.cs


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