Các huynh giúp giùm mình cái. Ko có lỗi khi chay F9 nhưng nhập ko đc.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
typedef struct node *ref;
struct node {
int key;
ref left;
ref right;
};
ref root;
ref getnode (int k){
ref p=new node;
p->key=k;
p->left=NULL;
p->right=NULL;
return p;
}
void insertnode(ref root, int k){
if(root==NULL){
ref p=getnode(k);
root=p;
}
else
if (k<root->key)
insertnode(root->left,k);
else
insertnode(root->right,k);
}
void visit(ref root){
if(root->key!=0){
printf("%d",root->key);
printf(", ");
}
}
void scan(ref root){
if(root==NULL) printf("cay rong");
else{
visit(root);
scan(root->left);
scan(root->right);
}
}
void main(){
int k;
ref root=NULL;
printf("nhap gia tri cho node:");
scanf("%d",&k);
while (k){
insertnode(root,k);
printf("nhap gia tri cho node:");
scanf("%d",&k);
}
scan(root);
getche();
}