Stack.h
class Struct_Stack
{
public:
int data;
Struct_Stack * next;
};
#include <iostream>
using namespace std;
class Stack
{
private:
Struct_Stack * L; //头
Struct_Stack * ptr; //压栈时用到
Struct_Stack * p; //显示时用到
public:
void push();
int pop();
void ShowStack();
int Interface();
Stack()
{
L = new Struct_Stack;
L->next = nullptr;
}
~Stack()
{
while(L !=nullptr)
{
Struct_Stack * q = L;
L = q->next;
cout << "正在删除" << q->data << endl; //查看正在释放的空间
delete q;
}
}
};
Stack.cpp
#include "Stack.h"
#include <iostream>
using namespace std;
void Stack :: push()
{
int temp;
int flag=1; //控制压入栈的循环
while (flag)
{
cout << "输入要入栈的数:" ;
cin >> temp;
if (tem