节点是私下宣布的

时间:2013-08-30 22:48:03

标签: c++ list linked-list private public

我没有永远用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
}

1 个答案:

答案 0 :(得分:0)

这几乎是一个语法问题。您可以定义这样的方法:

void ReversibleStack::Push(int Item)
{
    // ... 
}