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


C# Stack.Clear方法代码示例

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


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

示例1: GetWork

        private Dictionary<int, string> GetWork()
        {
            TimeSpan hold = TimeSpan.FromMinutes(90);

            Dictionary<int, string> all = new Dictionary<int, string>();

            var messages = Queue.GetMessages(32, hold).ToList();

            Stack<Task> tasks = new Stack<Task>(2000);

            while (messages.Count > 0)
            {
                foreach (var message in messages)
                {
                    string s = message.AsString;
                    JObject json = JObject.Parse(s);
                    int curId = json["cantonCommitId"].ToObject<int>();

                    if (!all.ContainsKey(curId))
                    {
                        all.Add(curId, s);
                    }
                    else
                    {
                        Console.WriteLine("Dupe id!");
                    }

                    tasks.Push(Queue.DeleteMessageAsync(message));

                    if (all.Count % 10000 == 0)
                    {
                        Console.WriteLine(all.Count);
                    }
                }

                // stop if we aren't maxing out
                if (messages.Count == 32)
                {
                    messages = Queue.GetMessages(32, hold).ToList();
                }
                else
                {
                    messages = new List<CloudQueueMessage>();
                }

                if (tasks.Count > 2000)
                {
                    Task.WaitAll(tasks.ToArray());
                    tasks.Clear();
                }
            }

            Task.WaitAll(tasks.ToArray());
            tasks.Clear();

            return all;
        }
开发者ID:joyhui,项目名称:NuGet.Services.Metadata,代码行数:57,代码来源:CatalogPageCommitJob.cs

示例2: DumpHumanReadable

	    public static void DumpHumanReadable(Transaction tx, string path, Page start)
	    {
		    using (var writer = File.CreateText(path))
		    {
                var stack = new Stack<Page>();
                stack.Push(start);
				writer.WriteLine("Root page #{0}",start.PageNumber);
			    while (stack.Count > 0)
			    {
					var currentPage = stack.Pop();
				    if (currentPage.IsLeaf)
				    {						
						writer.WriteLine();
						writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Leaf), Used: {3} : {4}", currentPage.PageNumber,currentPage.NumberOfEntries,currentPage.Flags, currentPage.SizeUsed, currentPage.CalcSizeUsed());
						if(currentPage.NumberOfEntries <= 0)
							writer.WriteLine("Empty page (tree corrupted?)");
					    
						
					    for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries;nodeIndex++)
					    {
						    var node = currentPage.GetNode(nodeIndex);
						    var key = currentPage.GetNodeKey(node);

							writer.WriteLine("Node #{0}, Flags = {1}, {4} = {2}, Key = {3}, Entry Size: {5}", nodeIndex, node->Flags, node->DataSize, MaxString(key.ToString(), 25), node->Flags == NodeFlags.Data ? "Size" : "Page",
                                SizeOf.NodeEntry(node));
					    }
						writer.WriteLine();
				    }
				    else if(currentPage.IsBranch) 
				    {
						writer.WriteLine();
						writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Branch), Used: {3} : {4}", currentPage.PageNumber, currentPage.NumberOfEntries, currentPage.Flags, currentPage.SizeUsed, currentPage.SizeUsed);

						var key = new Slice(SliceOptions.Key);
						for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
						{
							var node = currentPage.GetNode(nodeIndex);
							writer.WriteLine("Node #{2}, {0}  / to page #{1}, Entry Size: {3}", GetBranchNodeString(nodeIndex, key, currentPage, node), node->PageNumber, nodeIndex,
                                SizeOf.NodeEntry(node));
						}

						for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
						{
							var node = currentPage.GetNode(nodeIndex);
							if (node->PageNumber < 0 || node->PageNumber > tx.State.NextPageNumber)
							{
								writer.Write("Found invalid reference to page #{0}", currentPage.PageNumber);
								stack.Clear();
								break;
							}

							var child = tx.GetReadOnlyPage(node->PageNumber);
							stack.Push(child);
						}
						
						writer.WriteLine();
					}
			    }
		    }
	    }
开发者ID:cocytus,项目名称:ravendb,代码行数:60,代码来源:TreeDumper.cs

示例3: check

 static bool check(string arg)
 {
     char[] arrChar = arg.ToCharArray();
     if ((arrChar[0] == ')') || (arrChar.Length % 2 != 0)) return false;
     else
     {
         Stack<char> st = new Stack<char>();
         foreach(char c in arrChar)
         {
             if (c == ')' && st.Count != 0) st.Pop();
             else st.Push(c); 
         }
         if (st.Count == 0) { st.Clear(); return true; }
         else { st.Clear(); return false; }
     }
 }
开发者ID:dnshulga,项目名称:brackets,代码行数:16,代码来源:Program.cs

示例4: Main

    static void Main()
    {
        Stack<int> myStack = new Stack<int>();
            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);
            myStack.Push(4);
            myStack.Push(5);
            myStack.Push(6);

            int[] stackToArray = myStack.ToArray();
            Console.Write("{");
            for (int i = 0; i < stackToArray.Length-1; i++)
            {
                Console.Write(stackToArray[i] + ", ");
            }

            Console.Write(stackToArray[stackToArray.Length-1]+"}");
            Console.WriteLine();
            Console.WriteLine("the count="+myStack.Count);

            Console.WriteLine();
            Console.WriteLine(myStack.Peek());
            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Peek());
            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Peek());
            Console.WriteLine("the count="+myStack.Count);

            Console.WriteLine(myStack.Contains(111));

            myStack.Clear();
            Console.WriteLine("the count="+myStack.Count);
    }
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:34,代码来源:ImplementStack.cs

示例5: FindPath

        public static IEnumerable<String> FindPath(string start, string end, HashSet<string> words)
        {
            //build graph in O(N^2)
            var graph = BuildGraph(words);

            //bfs in O(V+E)
            var edgeTo = BuildEdgeTo(graph, start, end);

            //build a stack with path going from end to start
            var path = new Stack<string>();
            string word = end;
            while (!word.Equals(start))
            {
                path.Push(word);

                if (!edgeTo.ContainsKey(word))
                {
                    path.Clear();
                    break;
                }

                word = edgeTo[word];
            }

            path.Push(start);
            return path;
        }
开发者ID:juliolins,项目名称:interview,代码行数:27,代码来源:WordDistance.cs

示例6: Main

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).Distinct().ToArray();

            bool flag = false;
            int possibleSubsets = (int)Math.Pow(2, arr.Length);
            for (int mask = 0; mask <= possibleSubsets; mask++)
            {
                Stack<int> subset = new Stack<int>();
                for (int i = 0; i < arr.Length; i++)
                {
                    if ((mask & (1 << i)) != 0)
                    {
                        subset.Push(arr[i]);
                    }
                }
                if (subset.Sum() == n && subset.Count != 0)
                {
                    Console.WriteLine(String.Join(" + ", subset) + " = " + n);
                    flag = true;
                }
                subset.Clear();
            }
            if (!flag)
            {
                Console.WriteLine("No matching subsets.");
            }
        }
开发者ID:PlamenNeshkov,项目名称:Advanced-CSharp,代码行数:29,代码来源:SubsetSums.cs

示例7: BruteForce

        static long BruteForce(int times)
        {
            long i = 2 * 3 * 5 * 7;
            var primeFactors = GetPrimeFactors(100);
            var stack = new Stack<long>();
            while (true)
            {
                if (HasDistinctPrimeFactors(i, primeFactors, times))
                {
                    stack.Push(i);
                }
                else
                {
                    stack.Clear();
                }

                if (stack.Count == times)
                {
                    break;
                }
                i++;

            }
            var count = stack.Count - 1;
            for (int s = 0; s < count; s++)
            {
                stack.Pop();
            }
            return stack.Pop();
        }
开发者ID:david--liu,项目名称:code_kata,代码行数:30,代码来源:Problem47.cs

示例8: Apply

		public void Apply(Menu m)
		{
			m.Name = Name;
		    m.Items = new List<MenuItem>();

		    var j = new Stack<MenuItem>();
            foreach (var i in Items)
            {
                var a = new MenuItem {Name = i.Name, Type = i.Type, Location = i.Location};
                if (i.Indent == 0)
                {
                    j.Clear();
                    j.Push(a);
                    m.AddItem(a);
                }
                else
                {
                    // rewind the that stack until we reach the parent node. creates the
                    // effect  the stack always represents a 'stair-step' pattern
                    while (j.Count > i.Indent) j.Pop();
                    j.Peek().AddItem(a);
                    j.Push(a);
                }
            }
		}
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:25,代码来源:MenuController.cs

示例9: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        string errorDesc;

        int[] operands = new int[] { };
        TestLibrary.TestFramework.BeginScenario("PosTest2: remove all the elements from an empty stack.");
        try
        {
            Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
            operandStack.Clear();
            if (0 != operandStack.Count)
            {
                errorDesc = "Failed to clear stack " + this.GetStackData(operandStack);
                TestLibrary.TestFramework.LogError("P002.1", errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("P002.2", errorDesc);
            retVal = false;
        }

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

示例10: LargestRectangleArea

        private int LargestRectangleArea(int[] height)
        {
            int[] answers = new int[height.Length];
            Stack<int> stack = new Stack<int>();

            for (int i = 0; i < height.Length; i++)
            {
                while (stack.Count > 0 && height[stack.Peek()] >= height[i])
                {
                    stack.Pop();
                }
                int leftEdge = stack.Count > 0 ? stack.Peek() : -1;
                answers[i] = i - leftEdge - 1;
                stack.Push(i);
            }

            int max = 0;
            stack.Clear();
            for (int i = height.Length - 1; i >= 0; i--)
            {
                while (stack.Count > 0 && height[stack.Peek()] >= height[i])
                {
                    stack.Pop();
                }
                int rightEdge = stack.Count > 0 ? stack.Peek() : height.Length;
                answers[i] += rightEdge - i - 1;
                stack.Push(i);

                int current = height[i] * (answers[i] + 1);
                max = Math.Max(current, max);
            }

            return max;
        }
开发者ID:bluesteyes,项目名称:LeetSharp,代码行数:34,代码来源:Q085_MaximalRectangle.cs

示例11: Main

        static void Main(string[] args)
        {
            Stack<int> numbers = new Stack<int>();

            numbers.Push(4);
            numbers.Push(5);
            numbers.Push(5);
            numbers.Push(6);
            numbers.Push(7);
            numbers.Push(2);
            numbers.Push(22);
            numbers.Push(33);
            numbers.Push(14);
            Console.WriteLine(numbers.Count);

            Console.WriteLine(numbers.Pop());
            Console.WriteLine(numbers.Pop());
            Console.WriteLine(numbers.Peek());
            Console.WriteLine(numbers.Count);

            Console.WriteLine(numbers.Contains(5));
            Console.WriteLine(numbers.Contains(55));

            numbers.Clear();
            numbers.Push(44);
            Console.WriteLine(numbers.Count);
        }
开发者ID:Gardax,项目名称:CSharpExercises,代码行数:27,代码来源:Program.cs

示例12: Main

 static void Main()
 {
     var test = new Stack<int>();
     test.Push(1);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(2);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(3);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(4);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(5);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(6);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Push(7);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The stack count: {0}", test.Count);
     test.Pop();
     test.Pop();
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The stack count: {0}", test.Count);
     Console.WriteLine(test.Peek());
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The stack count: {0}", test.Count);
     test.Clear();
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The stack count: {0}", test.Count);
     //test.Pop();                           //if uncommented this line should throw exception
 }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:30,代码来源:StackTest.cs

示例13: MoveTo

        public bool MoveTo(int destinationX, int destinationY, int requiredDistance = 0)
        {
            if (destinationX == _client.PlayerX && destinationY == _client.PlayerY)
            {
                return true;
            }

            Node node = FindPath(_client.PlayerX, _client.PlayerY, _client.IsOnGround, _client.IsSurfing, destinationX, destinationY, requiredDistance);

            if (node != null)
            {
                Stack<Direction> directions = new Stack<Direction>();
                while (node.Parent != null)
                {
                    if (!node.Parent.IsSurfing && node.IsSurfing)
                    {
                        directions.Clear();
                        _client.UseSurfAfterMovement();
                    }
                    else
                    {
                        directions.Push(node.FromDirection);
                    }
                    node = node.Parent;
                }

                while (directions.Count > 0)
                {
                    _client.Move(directions.Pop());
                }
                return true;
            }
            return false;
        }
开发者ID:Rympex,项目名称:proshine,代码行数:34,代码来源:Pathfinding.cs

示例14: Main

    static void Main()
    {
        var stack = new Stack<int>();

        stack.Push(1);
        Console.WriteLine(stack);

        stack.Push(2);
        Console.WriteLine(stack);

        stack.Push(3);
        Console.WriteLine(stack);

        Console.WriteLine("Last: {0}", stack.Peek());

        Console.WriteLine("Count: {0}", stack.Count);
        Console.WriteLine("Contains 2: {0}", stack.Contains(2));

        Console.WriteLine("Capacity: {0}", stack.Capacity);
        stack.TrimExcess();
        Console.WriteLine("Capacity: {0}", stack.Capacity);

        while (stack.Count != 0)
            Console.WriteLine("Pop: {0}", stack.Pop());

        Console.WriteLine("Count: {0}", stack.Count);

        try
        {
            stack.Clear();
            stack.Pop();
        }
        catch (InvalidOperationException ex)
        {
            Console.WriteLine(ex.Message);
        }

        try
        {
            stack.Clear();
            stack.Peek();
        }
        catch (InvalidOperationException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:47,代码来源:Program.cs

示例15: ConvertRomanNumberToArabic

        public int ConvertRomanNumberToArabic(string romanFormatNumber)
        {
            var result = 0;

            var stack = new Stack<int>();
            var listOfArabicDigits = new List<int>();
            foreach (var currentCharOfRomanNumber in romanFormatNumber)
            {
                var currentArabicDigit = ConvertRomanDigitToArabic(currentCharOfRomanNumber);
                listOfArabicDigits.Add(currentArabicDigit);
            }

            foreach (var currentArabicDigit in listOfArabicDigits)
            {
                if (stack.Count != 0)
                {
                    if (currentArabicDigit < stack.Peek())
                    {
                        result += stack.Sum();
                        stack.Clear();
                        stack.Push(currentArabicDigit);
                    }
                    else if (currentArabicDigit == stack.Peek())
                    {
                        stack.Push(currentArabicDigit);
                    }
                    else
                    {
                        var subtrahend = stack.Sum();
                        var minuend = currentArabicDigit;
                        var currentArabicDigitAfterSubtraction = minuend - subtrahend;
                        result += currentArabicDigitAfterSubtraction;
                        stack.Clear();
                    }
                }
                else
                {
                    stack.Push(currentArabicDigit);
                }
            }

            var remainingDigits = stack.Sum();
            result += remainingDigits;

            return result;
        }
开发者ID:Confirmit,项目名称:Students,代码行数:46,代码来源:ConverterOfNumbers.cs


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