急急急!关于数据结构

来源:百度知道 编辑:UC知道 时间:2024/09/22 01:52:13
void reverse(Stack &st)
{
Stack st1,st2;
InitStack(st1);
InitStack(st2);
ElemType x;
while(!StackEmpty(st))
{
pop(st,x);
push(st1,x);
}
while(!StackEmpty(st1))
{
pop(st1,x);
push(st2,x);
}
while(!StackEmpty(st2))
{
pop(st2,x);
push(st,x);
}
}
这个为什么跑不了呢??
成功后加分!!
template<class elemtype>
int stack<elemtype>::push(const elemtype&e)
{
if(full())
{
return 0;
}
else
{
elem[count++]=e;
return 1;
}
}

template<class elemtype>
int stack<elemtype>::pop(elemtype&e)
{
if(empty())
{
return 0;
}
else
{
e=elem[count-1];
count--;
return 1;
}
}

你看俨然这个是没问题的吗!!

struct node//创建链表中的结点
{
ElemType data;
node<ElemType>*next;
node(){next=NULL;};
node(ElemType a,node<ElemType>*tmpptr):data(a),next(tmpptr){};
};
template<class ElemType>
class linkstack//创建栈
{
protected:
node<ElemType>*top;
void init();//初始化栈
public:
linkstack();
~linkstack();
int length()const;//求栈的长度
bool Empty()const;//判断栈是否为空
void clear();//将栈清空
void Push(const ElemType&e);//入栈函数
void Pop(ElemType&e);//出栈函数
void returnTop(ElemType&e)const;//返回栈顶元素
};

这些呢,有吗?

不一定就是这段代码有问题,有可能是你的pop和push的代码有问题。