我已经很久没有用C++编程了,真的很生疏。请帮帮我?我的任务是开发一个可逆的单链列表,但节点必须私下声明。我如何访问它们以从堆栈中推/弹出。还是我做错了?
#include <iostream>
using namespace std;
class ReversibleStack
{
public:
void push(int item);
int pop();
bool IsEmpty();
void Reverse();
private:
// let's build our singly linked list in private
typedef struct node
{
int first; //the first node
node *next; //pointer to the next node available
}node;
};
#include "ReversibleStack.h"
#include <iostream>
using namespace std;
//This is the Push function that pushes an item onto the stack
void Push(int Item)
{
node* current = first; // sets current pointer to first
node* new_item = Item; // sets previous pointer to NULL
node* next = current->next; // next item in stack
}
这几乎是一个语法问题。您定义的方法如下:
void ReversibleStack::Push(int Item)
{
// ...
}