使用队列实现树(链接列表实现)

发布于 2025-02-05 15:19:31 字数 538 浏览 2 评论 0原文

我正在尝试使用队列(链接列表实现)为树进行预订的遍历编码,

#include<iostream>
using namespace std;

class Node{
    public:
    int data;
    Node *rchild;
    Node *lchild;
};

class Queue{
   private:
 Node *front;
 Node *rear;
 
 
 public:
 Queue();
 void enqueue(Node* x);
 int dequeue();
 bool isEmpty();
 bool isFull();
 void display();
  
};
 
void enqueue(Node *x){
Node *t = new Node;
if(t == NULL) cout<<"Overflow!;
else{
rear++;
rear->data = x;

而我正在执行后部 - data; data = x;此语句无效,因为X不是整数。

我应该如何继续?

I am trying to code preorder traversal for a tree using queue(linked list implementation)

#include<iostream>
using namespace std;

class Node{
    public:
    int data;
    Node *rchild;
    Node *lchild;
};

class Queue{
   private:
 Node *front;
 Node *rear;
 
 
 public:
 Queue();
 void enqueue(Node* x);
 int dequeue();
 bool isEmpty();
 bool isFull();
 void display();
  
};
 
void enqueue(Node *x){
Node *t = new Node;
if(t == NULL) cout<<"Overflow!;
else{
rear++;
rear->data = x;

Now when i am doing rear->data = x; this statement is not valid because x is not an integer.

How should i proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文