C# 堆栈(Stack)

黄舟
黄舟 原创
2016-12-27 14:27:43 841浏览

堆栈(Stack)代表了一个后进先出的对象集合。

383.png

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# 堆栈(Stack)的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。