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


C# Queue.Peek方法代码示例

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


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

示例1: GenerateSequence

        private static List<int> GenerateSequence(int n, int count)
        {
            var queue = new Queue<int>();
            queue.Enqueue(n);

            var sequence = new List<int>();
            sequence.Add(n);

            for (int i = 1; i < count; i++)
            {
                var number = 0;

                if (i % 3 == 1)
                {
                    number = queue.Peek() + 1;
                }
                else if (i % 3 == 2)
                {
                    number = queue.Peek() * 2 + 1;
                }
                else
                {
                    number = queue.Dequeue() + 2;
                }

                sequence.Add(number);
                queue.Enqueue(number);
            }

            return sequence;
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:31,代码来源:Startup.cs

示例2: 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

示例3: Compile

        private Template Compile(Queue<Token> tokens, Func<Token, bool> stopCondition = null)
        {
            var templates = new List<Template>();
            while(tokens.Count > 0 && (stopCondition == null || !stopCondition(tokens.Peek())))
            {
                var current = tokens.Dequeue();

                if(current.Index > _index)
                    templates.Add(new LiteralTemplate { Value = _template.Substring(_index, current.Index - _index) });

                _index = current.Index + current.Length;

                if(current.Closing)
                    return new CompositeTemplate(templates);

                var builder = _builders[current.Name];
                var tmpl = builder(current, tokens);
                templates.Add(tmpl);
            }

            if(tokens.Count == 0 && _index < _template.Length)
                templates.Add(new LiteralTemplate { Value = _template.Substring(_index) });

            if(tokens.Count > 0 && _index < tokens.Peek().Index)
                templates.Add(new LiteralTemplate { Value = _template.Substring(_index, tokens.Peek().Index - _index) });

            return new CompositeTemplate(templates);
        }
开发者ID:hikirsch,项目名称:jquery-tmpl.net,代码行数:28,代码来源:TemplateCompiler.cs

示例4: Main

        static void Main(string[] args)
        {
            var fila = new Queue<String>();

            fila.Enqueue("adão");
            fila.Enqueue("eva");
            fila.Enqueue("caim");
            fila.Enqueue("abel");

            foreach (var item in fila)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            Console.WriteLine(fila.Peek());
            Console.WriteLine(fila.Peek());
            Console.WriteLine(fila.Peek());

            Console.WriteLine();

            while(fila.Count > 0)
                Console.WriteLine(fila.Dequeue());

            Console.WriteLine(fila.Count);

            //FIFO -> first in first out

            Console.ReadKey();
        }
开发者ID:50minutos,项目名称:ATENTO-OOP-CSharp,代码行数:31,代码来源:Program.cs

示例5: CombineMeshes

        public static void CombineMeshes(Queue<CombineInstance> items
            , byte area
            , InputGeometryCompiler compiler)
        {
            const int MaxTris = 65000;

            List<CombineInstance> combineInstancesPart = new List<CombineInstance>();
            byte[] areas = NMGen.CreateAreaBuffer(MaxTris, area);

            while (items.Count != 0)
            {
                int vertCount = 0;

                while (items.Count > 0
                    && (vertCount + items.Peek().mesh.vertexCount < MaxTris))
                {
                    vertCount += items.Peek().mesh.vertexCount;
                    combineInstancesPart.Add(items.Dequeue());
                }

                Mesh meshPart = new Mesh();

                meshPart.CombineMeshes(combineInstancesPart.ToArray(), true, true);

                compiler.AddTriangles(meshPart.vertices, meshPart.vertexCount
                    , meshPart.triangles, areas, meshPart.triangles.Length / 3);

                Object.DestroyImmediate(meshPart);

                combineInstancesPart.Clear();
            }
        }
开发者ID:kbengine,项目名称:unity3d_nav_critterai,代码行数:32,代码来源:MeshUtil.cs

示例6: Create

        /// <summary>
        /// Обработчик события создания папки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void Create(object sender, FileSystemEventArgs e)
        {
            if (Model.Dir.FindByPath(e.FullPath) == null)
            {
                Queue<string> queue = new Queue<string>();
                string[] dirs = Directory.GetDirectories(e.FullPath);
                string[] files = Directory.GetFiles(e.FullPath);
                foreach (string path in dirs)
                    queue.Enqueue(path);

                Model.Dir current_dir = Model.Dir.FindParentByPath(e.FullPath);

                current_dir = Model.Dir.Upload(current_dir.Id, e.FullPath);
                foreach (string one in files)
                    Model.File.Upload(current_dir.Id, one);

                while (queue.Count != 0)
                {
                    current_dir = Model.Dir.FindParentByPath(queue.Peek());
                    current_dir = Model.Dir.Upload(current_dir.Id, queue.Peek());

                    dirs = Directory.GetDirectories(queue.Peek());
                    files = Directory.GetFiles(queue.Dequeue());

                    foreach (string one in files)
                        Model.File.Upload(current_dir.Id, one);

                    foreach (string path in dirs)
                        queue.Enqueue(path);
                }

                Helpers.ApplicationHelper.SetCurrentTimeToSettings();
            }
        }
开发者ID:dkostenko,项目名称:2safe,代码行数:39,代码来源:Dirs.cs

示例7: TryParse

        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out ExtendDirective directive)
        {
            directive = null;
            if (remainingWords.Peek().Text != "@extend")
            {
                return false;
            }

            directive = new ExtendDirective(parent);
            directive.Name = remainingWords.Dequeue().Text.Substring(1);

            Expression expression;
            if (!Expression.TryParse(directive, remainingWords, out expression))
            {
                throw new Exception("errp?");
            }
            // remove ';'
            if (remainingWords.Peek().Text == ";")
            {
                remainingWords.Dequeue();
            }
            directive.Value = expression;

            return true;
        }
开发者ID:lzcd,项目名称:Crass,代码行数:25,代码来源:ExtendDirective.cs

示例8: Emit

        public string Emit(Message msg)
        {
            if (msg.Tags.Count > 0) { throw new NotImplementedException(); }

            var output = new StringBuilder();
            if(!string.IsNullOrEmpty(msg.Sender))
            {
                output.Append(":").Append(msg.Sender).Append(" ");
            }
            output.Append(msg.Command);

            var argcopy = new Queue<string>(msg.Argv);
            while(argcopy.Count > 0)
            {
                output.Append(" ");
                if (argcopy.Count == 1)
                {
                    if(String.IsNullOrEmpty(argcopy.Peek()) || argcopy.Peek().Contains(" ") || argcopy.Peek().First() == ':')
                    {
                        output.Append(":");
                    }
                }
                output.Append(argcopy.Dequeue().Replace("\n", "\\n").Replace("\r","\\r"));
            }
            return output.ToString();
        }
开发者ID:kythyria,项目名称:headlessmetaverseclient,代码行数:26,代码来源:Rfc1459Parser.cs

示例9: Main

 static void Main()
 {
     string input = Console.ReadLine();
     string[] elements = input.Split(' ');
     Queue<string> q = new Queue<string>();
     for (int i = 0; i < elements.Length; i++)
     {
         q.Enqueue(elements[i]);
     }
     string a = q.Peek();
     Console.Write(q.Dequeue());
     while (q.Count > 0)
     {
         if (q.Peek() == a)
         {
             Console.Write(" " + q.Dequeue());
         }
         else
         {
             Console.WriteLine();
             a = q.Peek();
             Console.Write(q.Dequeue());
         }
     }
 }
开发者ID:YPopova,项目名称:Source-Control-Systems,代码行数:25,代码来源:SequencesOfEqualStrings.cs

示例10: FindMaxOfEachSubArr

        //Time: O(n)
        //Not working. Need to implement a custom double ended queue.
        static void FindMaxOfEachSubArr(int[] arr, int k)
        {
            Queue<int> queue = new Queue<int>();    //To store indexes of array

            int i;
            //Process 1st k items in array
            for(i = 0; i < k; i++)
            {
                if(queue.Count == 0 || queue.Peek() < arr[i])
                    queue.Enqueue(i);
            }

            for (; i < arr.Length; i++)
            {
                Console.Write("{0} ", arr[queue.Peek()]);

                while (queue.Count > 0 && queue.Peek() <= (i - k))
                    queue.Dequeue();
                //need a double ended queue
                //while (queue.Count > 0 && arr[i] >= arr[queue.back()])
                  //  queue.DequeueBack();
                queue.Enqueue(i);
            }

            Console.Write("{0} ", arr[queue.Peek()]);//for last window
        }
开发者ID:pmiriyals,项目名称:Arrays,代码行数:28,代码来源:Program.cs

示例11: TryParse

        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out IncludeDirective directive)
        {
            directive = null;
            if (remainingWords.Peek().Text != "@include")
            {
                return false;
            }

            directive = new IncludeDirective(parent);
            // remove '@include'
            remainingWords.Dequeue();

            Expression expression;
            if (!Expression.TryParse(directive, remainingWords, out expression))
            {
                throw new Exception("errp?");
            }
            // remove ';'
            if (remainingWords.Peek().Text == ";")
            {
                remainingWords.Dequeue();
            }
            directive.Name = expression;

            return true;
        }
开发者ID:lzcd,项目名称:Crass,代码行数:26,代码来源:IncludeDirective.cs

示例12: ParseRawChapters

        /// <summary>
        /// Takes the chapter information from the form returned by the web
        /// service and organizes it into individual chapter objects
        /// </summary>
        private void ParseRawChapters()
        {
            Items.Clear();
            if (RawChapters.Count == 0)
                return;
            Queue<ChapterPart> queue = new Queue<ChapterPart>();
            foreach (var c in RawChapters)
                queue.Enqueue(c);

            while (queue.Count > 0)
            {
                Chapter c = new Chapter();
                if (queue.Count > 0 && queue.Peek().GetType() == typeof(ChapterNumber))
                {
                    int val;
                    var item = queue.Dequeue();
                    if (Int32.TryParse(item.Value, out val))
                    {
                        c.Index = val;
                    }
                }

                if (queue.Count > 0 && queue.Peek().GetType() == typeof(ChapterTitle))
                {
                    c.Title = queue.Dequeue().Value;
                }

                if (queue.Count > 0 && queue.Peek().GetType() == typeof(ChapterTime))
                {
                    var item = queue.Dequeue();
                    c.StartTime = ParseTime(item.Value);
                }
                Items.Add(c);
            }
        }
开发者ID:Inspirony,项目名称:Emby.Plugins,代码行数:39,代码来源:ChapterCollection.cs

示例13: 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();
        }
开发者ID:50minutos,项目名称:MOC-10266,代码行数:26,代码来源:Program.cs

示例14: Main

        public static void Main()
        {
            Console.Write("Enter the first number: ");

            Queue<int> queue = new Queue<int>();
            int number = 0;
            string input = Console.ReadLine();

            if (!int.TryParse(input, out number))
            {
                string message = string.Format(TextFormatErrorMessage, input);
                throw new InvalidCastException(message);
            }

            queue.Enqueue(number);
            int counter = 1;

            List<int> result = new List<int>();

            while (counter < Length)
            {
                queue.Enqueue(queue.Peek() + 1);
                queue.Enqueue((2 * queue.Peek()) + 1);
                queue.Enqueue(queue.Peek() + 2);
                result.Add(queue.Dequeue());
                counter += 3;
            }

            while (queue.Count != 0)
            {
                result.Add(queue.Dequeue());
            }

            Console.WriteLine(string.Join(", ", result.Take(50)));
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:35,代码来源:FirstNumbersByFormula.cs

示例15: Main

        public static void Main()
        {
            Console.Write("Enter N: ");
            int firstNumber = int.Parse(Console.ReadLine());

            int count = 50;

            var queue = new Queue<int>();

            queue.Enqueue(firstNumber);

            for (int i = 0; i < count; i++)
            {
                queue.Enqueue(queue.Peek() + 1);
                queue.Enqueue(2 * queue.Peek() + 1);
                queue.Enqueue(queue.Peek() + 2);

                Console.Write(queue.Dequeue() + " ");
            }

            while (queue.Count > 0)
            {
                Console.Write(queue.Dequeue() + " ");
            }
        }
开发者ID:EmilMitev,项目名称:Telerik-Academy,代码行数:25,代码来源:Starup.cs


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