为什么这个链栈的栈顶元素取出来是一段数字?
#include<iostream>
using namespace std;
template<class A>
struct stack
{
A date;
stack* next;
};
template<class A>
class stacklist
{
protected:stack* first = new stack;
public:
stacklist() { first->next = NULL; }
void in(A x);
bool get(A&x);
bool de();
void out();
};
template<class A>
void stacklist::in(A x)
{
stack* current = new stack;
current->date = x;
current->next = first->next;
first->next = current;
}
template<class A>
bool stacklist::get(A &x)
{
if (first->next = NULL)return false;
if (first->next != NULL)
{
stack* current = new stack;
x = first->next->date;
return true;
}
}
template<class A>
bool stacklist::de()
{
if (first->next == NULL)return false;
else first->next = first->next->next;
return true;
}
template<class A>
void stacklist::out()
{
stack* prt = first->next;
while (prt != NULL) {
cout << prt->date << " ";
prt = prt->next;
}
}
void main()
{
stacklist<int>s, w, t;
int i;
for (i = 1;i <= 5;i++)
{
s.in(i);
}
s.out();cout << endl;
int x;
for (i = 1;i <= 5;i++)
{
s.get(x);
w.in(x);
s.de();
}
w.out();cout << endl;
for (i = 1;i <= 5;i++)
{
w.get(x);t.in(x);
w.de();
}
t.out();
}