C# 堆栈(Stack)
2015-05-06 20:49
330 查看
堆栈(Stack)代表了一个后进先出的对象集合。
using System;
using System.Collections;
namespace CollectionsApplication
{
class Program
{
static void Main(string[] args)
{
Stack st = new Stack();
st.Push('A');
st.Push('M');
st.Push('G');
st.Push('W');
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
st.Push('V');
st.Push('H');
Console.WriteLine("The next poppable value in stack: {0}",
st.Peek());
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
Console.WriteLine("Removing values ");
st.Pop();
st.Pop();
st.Pop();
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
}
}
}
using System;
using System.Collections;
namespace CollectionsApplication
{
class Program
{
static void Main(string[] args)
{
Stack st = new Stack();
st.Push('A');
st.Push('M');
st.Push('G');
st.Push('W');
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
st.Push('V');
st.Push('H');
Console.WriteLine("The next poppable value in stack: {0}",
st.Peek());
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
Console.WriteLine("Removing values ");
st.Pop();
st.Pop();
st.Pop();
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
}
}
}
相关文章推荐
- C#使用foreach语句遍历堆栈(Stack)的方法
- C# 队列(Queue)和 堆栈(Stack)
- C# 堆栈(Stack)
- c#基础知识---集合之堆栈(Stack)
- Stack-C#数组构造堆栈
- C# 队列(Queue)和 堆栈(Stack)
- C# 堆栈(Stack)
- C# 堆栈和堆 Heap & Stack
- Stack-c#堆栈计算表达式
- C#项目中发生PInvokeStackImbalance异常,堆栈不对称异常
- C# 堆栈(Stack)
- Stack-C#堆栈-实现进制转换
- C# 堆栈与堆(托管堆)
- C# ConcurrentStack实现
- ZOJ 1004 Anagrams by Stack(dfs堆栈)
- C#调用C DLL:调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配
- 【Java集合的详细研究9】Java堆栈(stack)的使用方法
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- 线程堆栈大小 pthread_attr_setstacksize 的使用
- 堆栈和托管堆 c#