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


C# Stack类代码示例

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


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

示例1: GetValue

 public IItem GetValue(IDictionary<string, IItem> variables) {
   var stack = new Stack<object>();
   int i = 0;
   try {
     for (; i < tokens.Count; i++) {
       var token = tokens[i];
       double d;
       if (TryParse(token, out d)) {
         stack.Push(d);
       } else if (token.StartsWith("\"")) {
         stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace("\\\"", "\"")));
       } else if (token.StartsWith("'")) {
         stack.Push(token.Substring(1, token.Length - 2).Replace("\\'", "'"));
       } else {
         Apply(token, stack, variables);
       }
     }
   } catch (Exception x) {
     throw new Exception(string.Format(
       "Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine,
       Formula, i, TokenWithContext(tokens, i, 3),
       string.Join(Environment.NewLine, stack.Select(AsString))),
       x);
   }
   if (stack.Count != 1)
     throw new Exception(
       string.Format("Invalid final evaluation stack size {0} (should be 1) in formula '{1}'",
       stack.Count, Formula));
   var result = stack.Pop();
   if (result is string) return new StringValue((string)result);
   if (result is int) return new IntValue((int)result);
   if (result is double) return new DoubleValue((double)result);
   if (result is bool) return new BoolValue((bool)result);
   return null;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:35,代码来源:Calculator.cs

示例2: BufferManager

 public BufferManager(Int32 totalBytes, Int32 totalBufferBytesInEachSaeaObject)
 {
     totalBytesInBufferBlock = totalBytes;
     this.currentIndex = 0;
     this.bufferBytesAllocatedForEachSaea = totalBufferBytesInEachSaeaObject;
     this.freeIndexPool = new Stack<int>();
 }
开发者ID:Cocotus,项目名称:SocketAsyncServerAndClient,代码行数:7,代码来源:BufferManager.cs

示例3: Main

        static void Main(string[] args)
        {
            const int NumberOfAnimals = 10;
            Stack<Animal> animalStack = new Stack<Animal>();
            Queue<Animal> animalQueue = new Queue<Animal>();

            Console.WriteLine("/// ORDER OF ENTRY...");
            Random r = new Random();
            for (int index = 0; index < NumberOfAnimals; index++)
            {
                var animalShouldBeCat = (r.Next(2) == 0);
                uint nextWeight = (uint)r.Next(10, 40);
                Animal nextAnimal = animalShouldBeCat ? (Animal)(new Cat(nextWeight, "John")) : (Animal)(new Dog(nextWeight, "Dave"));
                animalStack.Push(nextAnimal);
                animalQueue.Enqueue(nextAnimal);
                Console.WriteLine(nextAnimal);
            }

            Console.WriteLine();
            Console.WriteLine("/// OUTPUT FROM STACK...");
            foreach (Animal animal in animalStack)
            {
                Console.WriteLine(animal);
            }

            Console.WriteLine();
            Console.WriteLine("/// OUTPUT FROM QUEUE...");
            foreach (Animal animal in animalQueue)
            {
                Console.WriteLine(animal);
            }
        }
开发者ID:JackMorris,项目名称:LCS3,代码行数:32,代码来源:Program.cs

示例4: GetRecursiveDependentsAsync

        ///<summary>Gets all files that indirectly depend on the specified file.</summary>
        public async Task<IEnumerable<string>> GetRecursiveDependentsAsync(string fileName)
        {
            HashSet<GraphNode> visited;
            fileName = Path.GetFullPath(fileName);
            using (await rwLock.ReadLockAsync())
            {
                GraphNode rootNode;
                if (!nodes.TryGetValue(fileName, out rootNode))
                    return Enumerable.Empty<string>();

                var stack = new Stack<GraphNode>();
                stack.Push(rootNode);
                visited = new HashSet<GraphNode> { rootNode };
                while (stack.Count > 0)
                {
                    foreach (var child in stack.Pop().Dependents)
                    {
                        if (!visited.Add(child)) continue;
                        stack.Push(child);
                    }
                }
                // Don't return the original file.
                visited.Remove(rootNode);
            }
            return visited.Select(n => n.FileName);
        }
开发者ID:kodybrown,项目名称:WebEssentials2013,代码行数:27,代码来源:DependencyGraph.cs

示例5: Validate

        public static bool Validate(string lineOfMarkupLanguage)
        {
            string[] splitted = lineOfMarkupLanguage.Split(new char[] { '>' }, StringSplitOptions.RemoveEmptyEntries);
            Stack<string> mainStack = new Stack<string>();

            foreach (var tag in splitted)
            {
                if (IsOpeniningTag(tag))
                {
                    mainStack.Push(tag);
                }
                else
                {
                    if (mainStack.Count == 0)
                    {
                        return false;
                    }

                    string currentOpeningTag = mainStack.Pop();
                    if (!SpecialComparer(currentOpeningTag, tag))
                    {
                        return false;
                    }
                }
            }

            return (mainStack.Count == 0);
        }
开发者ID:vanndann,项目名称:TelerikAcademy,代码行数:28,代码来源:Program.cs

示例6: SaveAllConncectedComponents

    private static void SaveAllConncectedComponents(Node<int> node,
        HashSet<int> visitedNodes, List<string> connectedComponents)
    {
        string graphs = string.Empty;
        Stack<Node<int>> nodesStack = new Stack<Node<int>>();
        nodesStack.Push(node);

        while (nodesStack.Count > 0)
        {
            Node<int> currentNode = nodesStack.Pop();
            visitedNodes.Add(currentNode.Value);
            graphs += " -> " + currentNode.Value;

            foreach (var child in currentNode.Children)
            {
                if (!visitedNodes.Contains(child.Value))
                {
                    visitedNodes.Add(child.Value);
                    nodesStack.Push(child);
                }
            }
        }

        connectedComponents.Add(graphs.Substring(4));
    }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:25,代码来源:Demo.cs

示例7: SpinOff

 public ExpansionContext SpinOff(MethodBase callee)
 {
     Stack.Contains(callee).AssertFalse();
     var new_stack = new Stack<MethodBase>();
     callee.Concat(Stack).Reverse().ForEach(new_stack.Push);
     return new ExpansionContext(new_stack, Scope, Names, Env){Parent = this};
 }
开发者ID:xeno-by,项目名称:conflux,代码行数:7,代码来源:ExpansionContext.cs

示例8: makeWhere

		private string makeWhere(Uri url)
		{
			Stack<string> hostStack = new Stack<string>(url.Host.Split('.'));
			StringBuilder hostBuilder = new StringBuilder('.' + hostStack.Pop());
			string[] pathes = url.Segments;

			StringBuilder sb = new StringBuilder();
			sb.Append("WHERE (");

			bool needOr = false;
			while (hostStack.Count != 0) {
				if (needOr) {
					sb.Append(" OR");
				}

				if (hostStack.Count != 1) {
					hostBuilder.Insert(0, '.' + hostStack.Pop());
					sb.AppendFormat(" host = \"{0}\"", hostBuilder.ToString());
				} else {
					hostBuilder.Insert(0, '%' + hostStack.Pop());
					sb.AppendFormat(" host LIKE \"{0}\"", hostBuilder.ToString());
				}

				needOr = true;
			}

			sb.Append(')');
			return sb.ToString();
		}
开发者ID:nico-lab,项目名称:niconama-ocv,代码行数:29,代码来源:Firefox3CookieGetter.cs

示例9: StartNavigationLink

 protected void StartNavigationLink(Stack<ResponseNode> nodeStack, string linkName)
 {
     nodeStack.Push(new ResponseNode
     {
         LinkName = linkName,
     });
 }
开发者ID:rexwhitten,项目名称:Simple.OData.Client,代码行数:7,代码来源:ResponseReaderBase.cs

示例10: StartEntry

 protected void StartEntry(Stack<ResponseNode> nodeStack)
 {
     nodeStack.Push(new ResponseNode
     {
         Entry = new AnnotatedEntry(new Dictionary<string, object>())
     });
 }
开发者ID:rexwhitten,项目名称:Simple.OData.Client,代码行数:7,代码来源:ResponseReaderBase.cs

示例11: StartFeed

 protected void StartFeed(Stack<ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations)
 {
     nodeStack.Push(new ResponseNode
     {
         Feed = new AnnotatedFeed(new List<AnnotatedEntry>()),
     });
 }
开发者ID:rexwhitten,项目名称:Simple.OData.Client,代码行数:7,代码来源:ResponseReaderBase.cs

示例12: GetChunkStack

 private static Stack<WeakReference> GetChunkStack(int size)
 {
     Stack<WeakReference> s;
     if (!_chunks.TryGetValue(size, out s))
         s = _chunks[size] = new Stack<WeakReference>();
     return s;
 }
开发者ID:patrickbird,项目名称:basespace-csharp-sdk,代码行数:7,代码来源:BufferPool.cs

示例13: GetBracketMismatch

        //Returns the location of bracket mismatch
        //Rewrite this to make use of better suited container for brackets
        public int GetBracketMismatch(string code)
        {
            Dictionary<char, char> bracketMap = new Dictionary<char, char>()
            { {'{', '}'}, {'(', ')'}, {'[', ']'}, {'<', '>'} };//, {'\'', '\''} }; //{} () [] <> "" ''
            Stack<char> bracketStack = new Stack<char>();
            int counter = 0;

            foreach (char c in code)
            {
                if("(){}<>".Contains(c))
                {
                    if (!")}>".Contains(c))
                    {
                        bracketStack.Push(c);
                    }
                    else if (bracketMap.Any(q => q.Key == bracketMap[bracketStack.Last()]))
                    {
                        bracketStack.Pop();
                    }
                    else
                    {
                        return counter;
                    }
                }
                counter++;
            }

            return -1;
        }
开发者ID:remco138,项目名称:amanda,代码行数:31,代码来源:Tags.cs

示例14: Print

        private static void Print(Stack<int> stack)
        {
            while (stack.Count > 0)
            {
                if (stack.Count == 1)
                {
                    Console.Write(stack.Pop());
                }
                else
                {
                    Console.Write(stack.Pop() + ",");
                }

            }
            Console.WriteLine();
            for (int i = 0; i < labyrinth.GetLength(0); i++)
            {
                for (int j = 0; j < labyrinth.GetLength(1); j++)
                {
                    Console.Write("{0, 2} ", labyrinth[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
开发者ID:kikooo52,项目名称:TelerikAkademy,代码行数:25,代码来源:Program.cs

示例15: CheckPath

        private static void CheckPath(int row, int col, int count, Stack<int> stack)
        {
            if (row < 0 || col < 0 ||
                row >= labyrinth.GetLength(0) || col >= labyrinth.GetLength(1))
            {
                return;
            }

            if (labyrinth[row, col] == "e")
            {
                Console.WriteLine("Exit found at [{0},{1}]", row, col);
                Print(new Stack<int>(stack));
            }

            if (labyrinth[row, col] != " ")
            {
                return;
            }

            stack.Push(count);
            labyrinth[row, col] = count.ToString();
            count++;
            CheckPath(row, col - 1, count, stack);
            CheckPath(row - 1, col, count, stack);
            CheckPath(row, col + 1, count, stack);
            CheckPath(row + 1, col, count, stack);

            labyrinth[row, col] = " ";
            if (stack.Count > 0)
            {
                stack.Pop();
            }
        }
开发者ID:kikooo52,项目名称:TelerikAkademy,代码行数:33,代码来源:Program.cs


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