?? genstack.h
字號:
// genstack.h Definition of the generic Stack class and generic
// implementation functions.
#include <stdlib.h>
#include <iostream.h>
const char BOTTOM = 'b';
const char EXPREND = '#';
const char NUMBER = 'n';
const int MAX = 100;
template <class AnyType>
class Stack
{ public: Stack (); // constructor
void Push (AnyType x); // push x onto stack
AnyType Pop (); // pop and return top item
AnyType Top (); // return a copy of top item
private: AnyType cells[MAX]; // allow MAX entries
int current_top; // index of current top
void Serror (char *); // error message function
};
template <class AnyType>
Stack<AnyType>::Stack ()
{ current_top = 0;
}
template <class AnyType>
void Stack<AnyType>::Serror (char *errmes)
{ cerr << errmes << endl;
exit(0);
}
template <class AnyType>
void Stack<AnyType>::Push (AnyType x)
{ if (current_top <= MAX)
cells[current_top++] = x;
else Serror("stack overflow");
}
template <class AnyType>
AnyType Stack<AnyType>::Pop ()
{ if (current_top == 0)
Serror ("stack underflow");
return (cells[--current_top]);
}
template <class AnyType>
AnyType Stack<AnyType>::Top ()
{ return (cells[current_top -1]);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -