首页 > Windows开发 > 详细

36. C# -- 堆栈(stack)

时间:2015-05-25 20:36:08      阅读:240      评论:0      收藏:0      [点我收藏+]

堆栈(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("Push V, H to the stack.");
            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 3 values ");
st.Pop();
st.Pop();
st.Pop();
            Console.WriteLine("Current stack: ");
            foreach (char c in st)
{
                Console.Write(c + " ");
}
            Console.ReadLine();
}
}
}

参考:

http://www.2cto.com/kf/201505/397728.html

 


本文出自 “Ricky's Blog” 博客,请务必保留此出处http://57388.blog.51cto.com/47388/1655017

36. C# -- 堆栈(stack)

原文:http://57388.blog.51cto.com/47388/1655017

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!