C# Stack

黄舟
Release: 2016-12-27 14:27:43
Original
1156 people have browsed it

Stack (Stack) represents a last-in-first-out collection of objects.

C# 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 + " ");            
         }        
         }    
         }}
Copy after login

The above is the content of C# Stack. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template