C# 集合类(三):Stack

Stack:栈,表示对象的简单的后进先出非泛型集合。Push方法入栈,Pop方法出栈。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            Stack sk 
= new Stack();
            Stack sk2 
= new Stack();
            
foreach (int i in new int[41234 })
            
{
                sk.Push(i);
//入栈
                sk2.Push(i);
            }


            
foreach (int i in sk)
            
{
                Console.WriteLine(i);
//遍历
            }


            sk.Pop();
//出栈
            Console.WriteLine("Pop");
            
foreach (int i in sk)
            
{
                Console.WriteLine(i);
            }


            sk2.Peek();
//弹出最后一项不删除
            Console.WriteLine("Peek");
            
foreach (int i in sk2)
            
{
                Console.WriteLine(i);
            }

        }

    }

}


posted @ 2008-01-14 12:46  无锋不起浪  阅读(1836)  评论(1编辑  收藏  举报