class stack_class
{
private:
struct stack_struct *head;
public:
stack_class();
~stack_class();
void pushNumber(int number);
void popNumber();
void findNumber();
void clearStack();
void sizeFinder();
void printStack();
};
void stack_class::popNumber()
{
stack_struct *pointerPop=NULL,*pointerPop2=NULL;
int popCounter=0,i=0;
pointerPop2=tailPointer;
if(head==NULL)
{
cout<<"\nNo Member to Delete.\n";
}
else
{
while(pointerPop2)
{
popCounter++;
//cout<<pointerFunc3->number<<endl;
pointerPop2=pointerPop2->next_number;
}
pointerPop=tailPointer;
while(i<(popCounter-2))
{
pointerPop=pointerPop->next_number;
i++;
}
pointerPop->next_number=NULL;
delete head;
head=pointerPop;
}
}
void stack_class::printStack()
{
pointerFunc3=tailPointer;
if(tailPointer==NULL)
{
cout<<"\nNo Members in List.\n";
}
else
{
cout<<"\n\nList Is:\n";
while(pointerFunc3)
{
cout<<pointerFunc3->number<<endl;
pointerFunc3=pointerFunc3->next_number;
}
}
}
构造函数到类
stack_class::stack_class()
{
head=NULL;
}
这是我的代码,问题是,当我弹出最后一个数字并尝试打印列表时,它进入无限循环并打印垃圾。当我在列表中的所有内容都被删除后按下删除选项时,程序会冻结。有什么建议为什么会这样??我该如何解决?