Exemplo n.º 1
0
        private static void StackOperation()
        {
            DataStructure.Stack <string> stack = new DataStructure.Stack <string>();

            stack.Push("1");
            Console.WriteLine(stack.Peek());
            stack.Push("3");
            Console.WriteLine(stack.Peek());
            stack.Pop();
            Console.WriteLine(stack.Peek());
        }
Exemplo n.º 2
0
        /// <summary>
        /// using Stack
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ReverseString(string str)
        {
            string reversedString = "";

            DataStructure.Stack <char> chars = new DataStructure.Stack <char>(str.Length);
            foreach (char t in str)
            {
                chars.Push(t);
            }
            while (!chars.IsEmpty())
            {
                reversedString += chars.Pop();
            }
            return(reversedString);
        }