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()); }
/// <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); }