// Justin C. Miller
// made for : http://www.geocities.com/neonprimetime.geo/index.html
// 3-16-2001
// Description : Template Stack
// made on MS Visual C++ 6.0
#include
#include
const int max = 10 ;
template
class Stack{
private:
T stack[max] ;
int size ;
int top ;
public:
Stack(){
size = 0 ;
top = -1 ;
}
~Stack(){}
bool Push(T x){
if(top < max){
stack[top+1] = x ;
top = top + 1 ;
return true ;
}
return false ;
}
int Pop(){
if(top >= 0){
top = top - 1;
return stack[top + 1] ;
}
return -999999 ;
}
void PrintStack(){
cout << "Stack" << endl ;
cout << "-----" << endl ;
for(int i = top ; i >= 0 ; i--)
cout << stack[i] << endl ;
}
};
int main(){
Stack a ; // can put any type, int char string, etc in here
int x ;
for(int i = 0 ; i < 10 ; i++){
cout << "Please enter integer #" << (i+1) << endl ;
cin >> x ;
if(!a.Push(x)){
cout << "Stack is Full!" << endl ;
cout << "Number not inserted!" << endl ;
}
}
a.PrintStack() ;
system("pause") ;
cout << "\nThese 2 numbers are being popped of the stack" << endl ;
for(x = 0 ; x < 2 ; x++)
cout << a.Pop() << endl ;
a.PrintStack() ;
system("pause") ;
return 0 ;
}
               (
geocities.com/neonprimetime.geo/cpp)                   (
geocities.com/neonprimetime.geo)