, . . , .
template<__>
class _
{
_
};
class
_
, .
template<class Type>
class Stack
{
Type *s;
int maxlen;
enum EMPTY=-1;
int top;
public:
Stack(int size=1000):maxlen(size)
{
s=new Type[size];
top=EMPTY;
}
~Stack()
{
delete[]s;
}
void Reset
{
top=EMPTY;
}
void Push(Type c) {...}
Type Pop(){return s.top;}
Type Topof(){return s.top;}
Type Empty();
int Full();
}
template <class T>
class Stack
{ enum {EMPTY=-1};
T *s;
int man_len;
int top;
public:
Stack(int);
~Stack();
void Reset();
void Push();
T Pop();
T Topoff();
int Empty();
int Full();
};
, , . .
template <class T>
T Stack<T>::Topoff()
{
return s[top];
}
, , .
Stack<char>stk_ch; //
Stack<char*>stk_ch(200);
Stack<complex>stk_cmpx(300);
//
void Reverse(char *str[], int n)
{
Stack<char*>stk(n);
for(int i=0;i<n;i++)
{
stk.Push(str);
}
for(i=0;i<n;i++)
str[i]=stk.Pop();
}
. . , .. , , - .
template <class T, int size >
Stack<char>stk_ch;
Stack<char*>stk_ch(200);
Stack<complex>stk_cmpx(300);
Stack<char, 100> stk_ch;
Stack<char, 10> stk_ch(10);
Stack<char, 20> stk_ch(20);
, .
template <class T, int size=100>
typedef
typedef, .
typedef Stack<char> cstack;
catack stk_ch10(10);
, . Push . :
|
|
- , inline, . , , .
template<class T>
class Stack
{
...
void Push(T c);
...
};
inline void Stack<char *>::Push(char *c)
{
s[++top]=new char [strlen(c)++]
strcpy(s[top],c);
}
template<class P>
inline void Stack<T>::Push(T c)
{
s[++top]=c;
}
. , , . , , .
template<class P> class Matrix
{
...
friend void Number(); //
friend Vect<T>product(Vector <T>); //
...
};
, .