//stack.cpp
#include <iostream>
using namespace std;
template <class T> class Stack_Frame {
private:
Stack_Frame *next;
T content;
public:
Stack_Frame() {
next = NULL;
}
Stack_Frame(const T& obj) {
content = obj;
this->next = NULL;
}
T getContent() { return content; }
void setContent(T& t) { content = t; }
Stack_Frame *getNext() { return next; }
void setNext(Stack_Frame *p) { next = p; }
};
template <class U> class Stack{
private:
Stack_Frame<U> *top;
public:
Stack() {
top = NULL;
}
~Stack() {
Stack_Frame<U> *p = NULL;
Stack_Frame<U> *q = NULL;
if (top) {
for (p = top; p; ) {
q = p;
p = p->getNext();
delete q;
}
}
top = NULL;
}
void push(U obj) {
Stack_Frame<U>* pframe = new Stack_Frame<U>(obj);
pframe->setNext(top);
top = pframe;
}
void pop(U *p) {
Stack_Frame<U>* pframe = NULL;
if (top) {
pframe = top;
top = top->getNext();
(*p) = pframe->getContent();
}
}
};
int main() {
char ch;
Stack<char> cstack;
for (ch = 'a'; ch <= 'z'; ch++) {
cstack.push(ch);
}
ch = 0;
for (int i = 0; i < 26; i++) {
cstack.pop(&ch);
cout<<ch<<" ";
}
cout<<endl;
return 0;
}