c#堆栈的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Test191112 { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push(‘A‘); st.Push(‘B‘); st.Push(‘C‘); st.Push(‘D‘); Console.WriteLine("当前堆栈:"); foreach(char c in st){ Console.Write(c+" "); } Console.WriteLine(); st.Push(‘E‘); st.Push(‘F‘); Console.WriteLine("栈Stat顶部的元素值是:{0}",st.Peek()); if (st.Contains(‘D‘)) { Console.WriteLine("栈中已经存在这个元素了!"); } else { st.Push(‘0‘); } Console.WriteLine("当前堆栈:"); foreach (char c in st) { Console.Write(c + " "); } Console.WriteLine(); st.Pop(); st.Pop(); st.Pop(); Console.WriteLine("当前堆栈:"); foreach (char c in st) { Console.Write(c + " "); } Console.Read(); } } }