• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Collections.Stack类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Main

        private static void Main()
        {
            string inputSentence = SampleSentence;
            string splitPattern = @"(\s+|\s*\,\s*|\s*\-\s*|\s*\!|\s*\.)";
            string[] elements = Regex.Split(inputSentence, splitPattern);

            Stack words = new Stack();
            Queue separators = new Queue();
            StringBuilder result = new StringBuilder();

            foreach (var element in elements)
            {
                if (Regex.IsMatch(element, splitPattern))
                {
                    separators.Enqueue(element);
                }
                else if (Regex.IsMatch(element, @"\S"))
                {
                    words.Push(element);
                }
            }

            while (words.Count > 0)
            {
                result.Append(words.Pop());
                result.Append(separators.Dequeue());
            }

            Console.WriteLine(result);
        }
开发者ID:,项目名称:,代码行数:30,代码来源:


示例2: ReversePolishNotationEvaluator

        public ReversePolishNotationEvaluator()
        {
            output = new Queue();
            ops = new Stack();

            postfixExpression = string.Empty;
        }
开发者ID:BlueForeverI,项目名称:ExpressionCalculator,代码行数:7,代码来源:ReversePolishNotationEvaluator.cs


示例3: InputMapper

 public InputMapper(Dictionary<string, InputContext> contexts, int playerIndex)
 {
     _contexts = contexts;
     _activeContexts = new Stack<InputContext>();
     _callbacks = new List<Action<MappedInput>>();
     _currentFrameMappedInput = new MappedInput(playerIndex);
 }
开发者ID:ConjureETS,项目名称:OuijaMTLGJ2016,代码行数:7,代码来源:InputMapper.cs


示例4: ReadPassword

 public static string ReadPassword()
 {
     var passbits = new Stack<string>();
     //keep reading
     for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true))
     {
         if (cki.Key == ConsoleKey.Backspace)
         {
             //rollback the cursor and write a space so it looks backspaced to the user
             Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
             Console.Write(" ");
             Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
             passbits.Pop();
         }
         else
         {
             Console.Write("*");
             passbits.Push(cki.KeyChar.ToString());
         }
     }
     string[] pass = passbits.ToArray();
     Array.Reverse(pass);
     Console.Write(Environment.NewLine);
     return string.Join(string.Empty, pass);
 }
开发者ID:joeletizia,项目名称:RedditSharp,代码行数:25,代码来源:Program.cs


示例5: Evaluate

        public static mysToken Evaluate(
			mysSymbol symbol,
			mysToken value,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            // NOTICE THIS
            // since each function has it's own internal space
            // before grabbing our reference to the space in which
            // we want to define our symbol, we need to pop the
            // internal off, or we're going to be defining the symbol
            // in our internal space, i.e. it will scope out as soon as
            // we're done. So we pop the internal off, grab our reference
            // to the space outside of that, then push the internal back on.
            mysSymbolSpace top = spaceStack.Pop();
            mysSymbolSpace ss = spaceStack.Peek();

            if ( value.Type == typeof(mysFunction) ) {
                defineFunction(
                    symbol,
                    value.Value as mysFunction,
                    spaceStack.Peek()
                );
            } else {
                mysSymbolSpace space = symbol.DefinedIn( spaceStack );
                if ( space != null ) {
                    space.Define( symbol, value );
                } else {
                    ss.Define( symbol, value );
                }
            }

            spaceStack.Push( top );
            return null;
        }
开发者ID:Koneke,项目名称:Yukkuri,代码行数:35,代码来源:Core.cs


示例6: Map

        public IEnumerable<IPath> Map(object data)
        {
            JToken jToken = JToken.Parse(data.ToString());
            var propertyStack = new Stack<Tuple<JProperty, bool>>();

            return BuildPaths(jToken, propertyStack, jToken);
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:7,代码来源:JsonMapper.cs


示例7: RenderXml

        TextWriter tw; // where the output is going

        #endregion Fields

        #region Constructors

        public RenderXml(Report rep, IStreamGen sg)
        {
            r = rep;
            tw = sg.GetTextWriter();
            stkReportItem = new Stack();
            stkContainers = new Stack();
        }
开发者ID:bittercoder,项目名称:odd-reports,代码行数:13,代码来源:RenderXml.cs


示例8: InvokeEstablish

    void InvokeEstablish()
    {
      var types = new Stack<Type>();
      var type = GetType();

      do
      {
        types.Push(type);
#if NET_STANDARD
        type = type.GetTypeInfo().BaseType;
#else
        type = type.BaseType;
#endif

      } while (type != typeof (ContextSpecification));

      foreach (var t in types)
      {
        var fieldInfos = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

        FieldInfo establishFieldInfo = null;
        foreach (var info in fieldInfos)
        {
          if (info.FieldType.Name.Equals("Establish"))
            establishFieldInfo = info;
        }

        Delegate establish = null;

        if (establishFieldInfo != null) establish = establishFieldInfo.GetValue(this) as Delegate;
        if (establish != null) Exception = Catch.Exception(() => establish.DynamicInvoke(null));
      }
    }
开发者ID:iancooper,项目名称:Paramore,代码行数:33,代码来源:ContextSpecification.cs


示例9: ResolveTemplate

		private string ResolveTemplate (string tag, Stack<string> resolvestack)
		{
			string template = FindTemplate(tag);
			if (template == null) return Cache(tag, tag.Trim());
			string translation = ExpandTemplate(template, tag, resolvestack).Trim();
			return Cache(tag, translation);
		}
开发者ID:versionone,项目名称:VersionOne.Localization,代码行数:7,代码来源:Localizer.cs


示例10: depthFirstSearch

        /// <summary>
        /// returns true if path exists from startVertex to endVertex
        /// </summary>
        private bool depthFirstSearch(object startVertex, object endVertex)
        {
            var stack = new Stack();
            var vertextQueue = new Queue();
            bool found = false;

            graph.clearMarks();
            stack.Push(startVertex);
            do
            {
                object vertex = stack.Pop();

                if (vertex == endVertex) // general case when path is found
                    found = true;
                else
                {
                    if (!graph.isMarked(vertex)) // if not marked
                    {
                        graph.markVertex(vertex); // then mark that vertex
                        vertextQueue = graph.getToVertices(vertex); //get all adjecent vertexes

                        while (vertextQueue.Count > 0) // then for each of those adjecent vertexes
                        {
                            object item = vertextQueue.Dequeue();

                            if (!graph.isMarked(item))
                                stack.Push(item);
                        }
                    }
                }
            } while (stack.Count > 0 && !found);

            return found;
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:37,代码来源:DepthFirstSearch.cs


示例11: MarkNodes

        public Dictionary<HClusterNode,System.Drawing.Color> MarkNodes(List<string> toMark,System.Drawing.Color color)
        {
            Dictionary<HClusterNode, System.Drawing.Color> returnList = new Dictionary<HClusterNode, System.Drawing.Color>();
            Stack<HClusterNode> st = new Stack<HClusterNode>();
            HClusterNode current = null;

            st.Push(this);

            while (st.Count != 0)
            {
                current = st.Pop();
                if (current.joined == null || current.joined.Count == 0)
                {
                    foreach(var item in toMark)
                        if(current.setStruct.Contains(item))
                        {
                            returnList.Add(current,color);
                            break;
                        }
                }
                else
                    if (current.joined != null)
                        foreach (var item in current.joined)
                            st.Push(item);

            }
            return returnList;
        }
开发者ID:uQlust,项目名称:uQlust-ver1.0,代码行数:28,代码来源:hierarchicalCluster.cs


示例12: TagListViewProcessor

 public TagListViewProcessor(ListView listview)
 {
     _TagTable = new Hashtable(1023);
     _Tags = new Stack<string>();
     _Item_LV = listview;
     _Item_LV.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this._Item_LV_ItemCheck);
 }
开发者ID:justinlf,项目名称:RFIDManager,代码行数:7,代码来源:TagListViewProcessor.cs


示例13: LevelOrderBottom

        public IList<IList<int>> LevelOrderBottom(TreeNode root)
        {
            IList<IList<int>> result = new List<IList<int>>();
            if (root == null)
                return result;

            Stack<IList<int>> stack = new Stack<IList<int>>();
            Queue<TreeNode> queue = new Queue<TreeNode>();
            queue.Enqueue(root);
            while (queue.Count > 0)
            {
                IList<int> items = new List<int>();
                int num = queue.Count;
                for (int i = 0; i < num; i++)
                {
                    TreeNode node = queue.Dequeue();
                    items.Add(node.val);

                    if (node.left != null)
                        queue.Enqueue(node.left);
                    if (node.right != null)
                        queue.Enqueue(node.right);
                }
                stack.Push(items);
            }

            while (stack.Count > 0)
                result.Add(stack.Pop());

            return result;
        }
开发者ID:jeremyyang824,项目名称:Leetcode,代码行数:31,代码来源:OJ107_BinaryTreeLevelOrderTraversalII.cs


示例14: ZnajdzOtoczke

        public void ZnajdzOtoczke(List<Punkt> lista)
        {
            List<Punkt> listaTmp = new List<Punkt>();
            Stack stos = new Stack();

            stos.Push(lista[0]);
            stos.Push(lista[1]);
            stos.Push(lista[2]);

            listaTmp.Add(lista[0]);
            listaTmp.Add(lista[1]);
            listaTmp.Add(lista[2]);

            for (int i = 3; i < lista.Count; i++)
            {
                int j = i;
                while (ObliczDet(listaTmp[stos.Count - 2], listaTmp[stos.Count - 1], lista[i]) < 0)
                {
                    //Console.WriteLine(ObliczDet(lista[j - 2], lista[j - 1], lista[i]));
                    stos.Pop();
                    listaTmp.RemoveRange(stos.Count, 1);
                }
                stos.Push(lista[i]);
                listaTmp.Add(lista[i]);
            }
            int ileWierz = stos.Count;
            for (int i = 0; i < ileWierz; i++)
            {
                wierzcholki.Add((Punkt)stos.Pop());
            }
            wierzcholki.Reverse();
        }
开发者ID:krzSobin,项目名称:Algorytmy-projekt---Otoczka-wypukla-i-Monte-Carlo,代码行数:32,代码来源:Otoczka.cs


示例15: TrimString

        //Taken from http://stackoverflow.com/a/18884516 by pkuderov
        private static string TrimString(StringBuilder builder)
        {
            string initialString = builder.ToString();
            char[] s = new char[initialString.Length];
            char toRemove = '$';
            Stack<int> stack = new Stack<int>();

            for (int i = 0; i < s.Length; i++)
            {
                s[i] = initialString[i];
                if (s[i] == '(')
                    stack.Push(i);
                else if (s[i] == ')')
                {
                    int start = stack.Pop();
                    var endParanthesis = start == 0 && i == s.Length - 1;
                    var middleParanthesis = start != 0 && s[start - 1] == '(' && s[i + 1] == ')';
                    if (endParanthesis || middleParanthesis)
                    {
                        s[start] = s[i] = toRemove;
                    }
                }
            }
            var newString = new string((from c in s where c != toRemove select c).ToArray());
            return newString.Trim();
        }
开发者ID:MarkDeVerno,项目名称:WindowsAzure,代码行数:27,代码来源:ExpressionTranslator.cs


示例16: Dispose

 public void Dispose()
 {
     _dataStructureStack = null;
     _dataStack = null;
     _accumulator = null;
     _unicodeAccumulator = null;
 }
开发者ID:StephanieMak,项目名称:IoT-Maker-Den-NETMF,代码行数:7,代码来源:JSONParser.cs


示例17: Main

        static void Main(string[] args)
        {
            string frase; //string que contendra la frase digitada por el usuario
            Stack mipila = new Stack(); //Pila que contendra la frase por partes
            int contadorPalabrasIguales = 0; //contador que contara la cantidad de palabras iguales
            string valor;

            Console.WriteLine("Digite una frase: "); //Le indico que necesito que digite una frase
            frase = Console.ReadLine(); //Guardo la frase en la variable "frase"

            for (int i = 0; i < frase.Length; i++) //para i = 0 hasta que i sea menor al tamaño de la frase
            {
                mipila.Push(frase.Substring(i,1)); //Enviar a la pila una subcadena de la frase
            }
            for (int i = 0; i < frase.Length; i++)
            {
                valor = mipila.Pop().ToString();
                if (valor == frase.Substring(i,1))
                {
                    contadorPalabrasIguales++;
                }
            }
            if (contadorPalabrasIguales == frase.Length)
            {
                Console.WriteLine("La frase es palindromo");
            }
            else
            {
                Console.WriteLine("La frase no es palindromo");
            }
            Console.WriteLine("Presione una tecla para salir...");
            Console.ReadKey();
        }
开发者ID:sancas,项目名称:ProgramacionIII,代码行数:33,代码来源:Program.cs


示例18: CalculateTime

        public static void CalculateTime(Stack stack, int k)
        {
            // Add
            var startAdding = DateTime.Now;
            string test = "Test string";
            for (int i = 0; i < k; i++)
            {
                stack.Push(test);
            }
            var finishAdding = DateTime.Now;
            Console.WriteLine("Addition time (" + k + " elements) : " + stack.GetType() + "  " + (finishAdding - startAdding));

            // Search
            var startSearch = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                bool a = stack.Contains(test);
            }
            var finishSearch = DateTime.Now;
            Console.WriteLine("Search time (" + k + " elements) : " + stack.GetType() + "  " + (finishSearch - startSearch));

            // Remove
            k = 1000000;
            var startRemoving = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                stack.Pop();
            }
            var finishRemoving = DateTime.Now;
            Console.WriteLine("Removal time (" + k + " elements) : " + stack.GetType() + "  " + (finishRemoving - startRemoving) + "\n");
        }
开发者ID:yuliapetrova,项目名称:CSharpTasks,代码行数:31,代码来源:Program.cs


示例19: Expand

        internal static TreeViewItemViewModel Expand(TreeViewItemModelItemViewModel rootTreeViewItem, ModelItem modelItemToExpandTo)
        {
            Fx.Assert(modelItemToExpandTo != null && rootTreeViewItem != null, "rootTreeViewItem and modelItemToExpand should not have null value");

            // ModelItems with HidePropertyInOutlineViewAttribute are invisible in the designerTree.
            if (ExtensibilityAccessor.GetAttribute<HidePropertyInOutlineViewAttribute>(modelItemToExpandTo) != null)
            {
                return null;
            }

            Stack pathStack = new Stack();

            TreeViewItemViewModel itemToBeSelected = null;

            if (GetExpandingPath(modelItemToExpandTo, pathStack, new HashSet<ModelItem>()))
            {
                // If the root of modelItemToExpandTo differs from the root of the designerTree, it means modelItemToExpandTo doesn't belong to the designerTree.
                if (pathStack.Pop() != rootTreeViewItem.VisualValue)
                {
                    return null;
                }

                object item = null;
                TreeViewItemViewModel treeViewItem = rootTreeViewItem;
                TreeViewItemViewModel tempTreeViewItem = rootTreeViewItem;

                // Using the path to the root, expand the corresponding tree node. Ignore the items which is not visible on the designerTree.
                while (pathStack.Count > 0)
                {
                    if (tempTreeViewItem != null)
                    {
                        treeViewItem = tempTreeViewItem;
                        treeViewItem.IsExpanded = true;
                    }

                    item = pathStack.Pop();
                    tempTreeViewItem = (from child in treeViewItem.Children
                                        where (child is TreeViewItemModelItemViewModel && ((TreeViewItemModelItemViewModel)child).VisualValue == item as ModelItem)
                                        || (child is TreeViewItemModelPropertyViewModel && ((TreeViewItemModelPropertyViewModel)child).VisualValue == item as ModelProperty)
                                        || (child is TreeViewItemKeyValuePairModelItemViewModel && ((TreeViewItemKeyValuePairModelItemViewModel)child).VisualValue.Value == item as ModelItem)
                                        select child).FirstOrDefault();

                    // For TreeViewItemKeyValuePairModelItemViewModel, its path to the children is very complicated.
                    // Take Switch as example: Switch(ModelItem) -> Cases(ModelProperty) -> KeyDictionaryCollection(ModelItem) -> ItemsCollection(ModelProperty) -> ModelItemKeyValuePair<T, Activity>(ModelItem) -> Value(ModelProperty) -> Children
                    // All the path nodes except Switch and Children are invisible and can be ignored, the child node in the path is used twice to search for TreeViewItemKeyValuePairModelItemViewModel and its children in designerTree.
                    if (tempTreeViewItem is TreeViewItemKeyValuePairModelItemViewModel)
                    {
                        // For further searching
                        pathStack.Push(item);
                    }

                    if (pathStack.Count == 0)
                    {
                        itemToBeSelected = tempTreeViewItem;
                    }
                }
            }

            return itemToBeSelected;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:60,代码来源:DesignerTreeAutoExpandHelper.cs


示例20: Student

 public Student(string fname,string lname)
 {
     this.FirstName = fname;
     this.LastName = lname;
     Grades= new Stack();
     count++;
 }
开发者ID:JouYin-Chen,项目名称:AssignmentHW,代码行数:7,代码来源:Student.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Generic.PriorityQueue类代码示例发布时间:2022-05-26
下一篇:
C# Collections.SortedSet类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap