用泛型实现在数组模拟入栈出栈时多类型的使用

/*
 * Created by SharpDevelop.
 * User: ??
 * Date: 2008-2-3
 * Time: 9:14
 * 
 * ??????
 
*/


using  System;
class  Statck < T >
{
    
private T[] statck;
    
private int count;
    
public Statck(int size)
    
{
        statck 
= new T[size];
        count 
= 0;
    }

    
public void Push(T x)
    
{
        statck[count
++= x;
    }

    
public T Pop()
    
{
        
return statck[--count];
    }

}


class  Test
{
    
static void Main()
    
{
        Statck
<int> s = new Statck<int>(10);
        s.Push(
1);
        s.Push(
2);
        Console.WriteLine(s.Pop()
+s.Pop());
    }

}

你可能感兴趣的:(数组)