30/09/2018, 18:14
lỗi Error 1 error C2513: 'NODE *' : no variable declared before '='
báo lỗi Error 1 error C2513: ‘NODE *’ : no variable declared before ‘=’
#include<iostream>
using namespace std;
struct Node {
int data;
struct Node *pleft;
struct Node *pright;
};
typedef struct Node NODE;
typedef NODE* Tree;
void Init(Tree &t) {
Tree=NULL;
}
void Insert(Tree &t, int x) {
if(t==NULL) {
NODE *q = new NODE;
q ->data = x;
q->pleft = q->pright = NULL;
t = q;
} else {
if(x < t->data)
Insert(t->pleft, x);
else if(x > t->data)
Insert(t->pright, x);
}
}
void NLR(Tree t) {
if(t != NULL) {
cout<<t->data<<" ";
NLR(t->pleft);
NLR(t->pright);
}
}
void LNR(Tree t) {
if(t != NULL) {
NLR(t->pleft);
cout<<t->data<<" ";
NLR(t->pright);
}
}
void LRN(Tree t) {
if(t != NULL) {
LRN(t->pleft);
LRN(t->pright);
cout<<t->data<<" ";
}
}
int menu() {
int chon;
cout<<"--------------------------menu--------------------------
"
<<"1.
"
<<"2.
"
<<"3.
"
<<"0.thoat"
<<"--------------------------------------------------------
"
<<"chon: ";
cin>>chon;
return chon;
}
void main() {
int chon;
Tree t;
Init(t);
do {
chon = menu();
switch(chon) {
case 1: {
int x;
cout<<"nhap vao du lieu: ";
cin>>x;
Insert(t, x);
}
}
} while(chon != 0);
}
Bài liên quan
Tree
là kiểu dữ liệu, không thể gán bằngNULL
Sửa lại thành