// simulateStackusingArray.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
const int size =100;
template <typename T>
class IStack
{
public:
IStack();
T pop ();
int push (T);
int display();
private:
T IArray [size];
int count;
};
template <typename T>
IStack<T>::IStack()
{
for (int i =0; i<size; i++)
{
IArray[i] =0;
}
count=0;
}
template <typename T>
T IStack<T>::pop()
{
T temp =IArray[count-1];
count--;
return temp;
}
template <typename T>
int IStack<T>::push(T rhs)
{
IArray [count++]=rhs;
return0;
}
template <typename T>
int IStack<T>::display()
{
for (int i =0; i<count; i++)
{
cout << IArray[i] <<"";
}
return0;
}
//template <typename T>
//int IStack<T>::getcount()
//{
// return count;
//}
int main()
{
IStack<int> istack;
istack.push(2);
istack.push(4);
istack.push(3);
istack.pop();
istack.display();
return0;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/weiweitj/archive/2008/04/27/2336067.aspx