夫为剑者

示之以虚 开之以利 后之以发 先之以至

常用链接

统计

积分与排名

最新评论

2006.08.08

#ifndef STACK_TMP_H
#define STACK_TMP_H

#include <iostream.h>
#include <stdlib.h>

const int MaxStackSize = 50;

template <class T>
class Stack
{
private:
T StackList[MaxStackSize];
int top;
public:
Stack();
void Push(const T& item);
T Pop();
void ClearStack();
T Peek() const;
int StackEmpty() const;
int StackFull() const;
};

template <class T>
Stack<T>::Stack()
{
top = -1;
}

template <class T>
void Stack<T>::Push(const T& item)
{
if (top == MaxStackSize-1)
{
exit(1);
}
StackList[++top] = item;
}

template <class T>
T Stack<T>::Pop()
{
if (top == -1)
exit(1);
T tmp;
tmp = StackList[top--];
return tmp;
}

template <class T>
void Stack<T>::ClearStack()
{
top = -1;
}

template <class T>
T Stack<T>::Peek() const
{
if (top == -1)
exit(1);
return StackList[top];
}

template <class T>
int Stack<T>::StackEmpty() const
{
return (top == -1);
}

template <class T>
int Stack<T>::StackFull() const
{
return (top == MaxStackSize-1);
}

#endif

posted on 2006-08-09 09:44 vivip 阅读(69) 评论(0)  编辑 收藏 引用 所属分类: 自我监督


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理