next;//堆栈中的下一项 },c++,list,linked-list,private,public,C++,List,Linked List,Private,Public" /> next;//堆栈中的下一项 },c++,list,linked-list,private,public,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 } #包括 使用名称空间std; 类可逆堆栈 { 公众: 无效推送(int项); int-pop(); bool是空的(); 无效反向(); 私人: //让我们私下建立我们的单链表 类型定义结构节点 { int first;//第一个节点 node*next;//指向下一个可用节点的指针 }节点; }; #包括“ReversibleStack.h” #包括 使用名称空间std; //这是将项目推送到堆栈上的推送函数 无效推送(整数项) { node*current=first;//将当前指针设置为first node*new_item=item;//将上一个指针设置为NULL node*next=current->next;//堆栈中的下一项 }

以私有方式声明的节点 我从来没有用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 } #包括 使用名称空间std; 类可逆堆栈 { 公众: 无效推送(int项); int-pop(); bool是空的(); 无效反向(); 私人: //让我们私下建立我们的单链表 类型定义结构节点 { int first;//第一个节点 node*next;//指向下一个可用节点的指针 }节点; }; #包括“ReversibleStack.h” #包括 使用名称空间std; //这是将项目推送到堆栈上的推送函数 无效推送(整数项) { node*current=first;//将当前指针设置为first node*new_item=item;//将上一个指针设置为NULL node*next=current->next;//堆栈中的下一项 },c++,list,linked-list,private,public,C++,List,Linked List,Private,Public,这几乎是一个语法问题。您可以这样定义方法: void ReversibleStack::Push(int Item) { // ... } 简单的答案是:使用std::deque(根据定义,它是可逆的,因为您可以在两端按下/弹出)。严酷的现实:您需要回顾一些事情,例如指针用法、运算符new、区分大小写、类名限定符以及其他一些。

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

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

简单的答案是:使用
std::deque
(根据定义,它是可逆的,因为您可以在两端按下/弹出)。严酷的现实:您需要回顾一些事情,例如指针用法、
运算符new
、区分大小写、类名限定符以及其他一些。