what is wrong with the code of this program?

for the master c + +. I want to ask? what's wrong with this program listing? ... please help me ... This program tree ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <conio.h>
typedef struct Node{
int data;
Node *kiri;
Node *kanan;
}
void tambah(Node **root,int databaru){
if((*root) == NULL){
Node *baru;
baru = new Node;
baru->data = databaru;
baru->kiri = NULL;
baru->kanan = NULL;
(*root) = baru;
(*root)->kiri = NULL;
(*root)->kanan = NULL;
printf("Data bertambah!");
}
else if(databaru < (*root)->data)
tambah(&(*root)->kiri,databaru);
else if(databaru > (*root)->data)
tambah(&(*root)->kanan,databaru);
else if(databaru == (*root)->data)
printf("Data sudah ada!");
}
void preOrder(Node *root){
if(root != NULL){
printf("%d ",root->data);
preOrder(root->kiri);
preOrder(root->kanan);
}
}
void inOrder(Node *root){
if(root != NULL){
inOrder(root->kiri);
printf("%d ",root->data);
inOrder(root->kanan);
}
}
void postOrder(Node *root){
if(root != NULL){
postOrder(root->kiri);
postOrder(root->kanan);
printf("%d ",root->data);
}
}
void main(){
int pil,c;
Node *pohon,*t;
pohon = NULL;
do{
clrscr();
int data;
printf("MENU\n");
printf("1. Tambah\n");
printf("2. Lihat pre-order\n");
printf("3. Lihat in-order\n");
printf("4. Lihat post-order\n");
printf("5. Exit\n");
printf("Pilihan : "); scanf("%d",&pil);
switch(pil){
case 1: printf("Data baru : ");scanf("%d",&data);
tambah(&pohon,data);
break;
case 2: if(pohon!=NULL) preOrder(pohon);else printf("Masih kosong!");
break;
case 3: if(pohon!=NULL) inOrder(pohon);else printf("Masih kosong!");
break;
case 4: if(pohon!=NULL) postOrder(pohon);else printf("Masih kosong!");
break;
}
getch();
}while(pil!=5);
}





Last edited on
It's not wrong to post in your native language, but keep in mind that you're reducing the amount of people willing and able to help you drastically.

As for the problem, post the errors that you got.
ok I've changed the language.
I wrote:
As for the problem, post the errors that you got
Topic archived. No new replies allowed.