我正在尝试使用链表实现堆栈类这里是我的stack.h
// File: Stack.h
#ifndef STACK_H
#define STACK_H
class Stack
{
private:
struct linklst{
int num;
int* next;
};
linklst* top;
public:
Stack();
~Stack();
void push(int i);
int pop();
bool isempty();
};
#endif
Run Code Online (Sandbox Code Playgroud)
和我的堆栈.cpp
// Stack.cpp
#include"Stack.h"
using namespace std;
Stack::Stack(){
top = new linklst();
top->num = -1;
top->next = nullptr;
};
Stack::~Stack() {
linklst * r = new linklst();
while (true)
{
r = top;
top = top->next;
delete r;
}
delete top;
};
void Stack::push(int i){
linklst * …Run Code Online (Sandbox Code Playgroud)