RANDY MUKTI
ARIEF SETIAWAN
Kelompok :6
NIM : 20170801399
20180801243
20170801413
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct Node{
int data;
Node *kiri;
Node *kanan;
};
int count;
if((*root) == NULL){
Node *baru;
baru->data = databaru;
baru->kiri = NULL;
baru->kanan = NULL;
(*root) = baru;
(*root)->kiri = NULL;
(*root)->kanan = NULL;
printf("Data telah Dimasukkan");
tambah(&(*root)->kiri,databaru);
tambah(&(*root)->kanan,databaru);
if(root != NULL){
preOrder(root->kiri);
preOrder(root->kanan);
if(root != NULL){
inOrder(root->kiri);
printf("%d ",root->data);
inOrder(root->kanan);
if(root != NULL){
postOrder(root->kiri);
postOrder(root->kanan);
printf("%d ",root->data);
}
}
if((*root) == NULL){
search(&(*root)->kiri,cari);
search(&(*root)->kanan,cari);
printf("Data ditemukan!!!");
if((*root) == NULL){
hapus(&(*root)->kiri,del);
hapus(&(*root)->kanan,del);
(*root)=NULL;
int main(){
int pil,cari,del;
Node *pohon;
pohon = NULL;
do{
int data;
system("cls");
printf("================================\n");
printf("================================\n");
scanf("%d",&pil);
switch(pil){
case 1:
scanf("%d", &data);
tambah(&pohon,data);
break;
case 2:
printf("\nPreOrder : ");
if(pohon!=NULL) preOrder(pohon);
printf("\ninOrder : ");
if(pohon!=NULL) inOrder(pohon);
else printf("Data masih kosong");
printf("\npostOrder : ");
if(pohon!=NULL) postOrder(pohon);
break;
case 3:
scanf("%d", &cari);
search(&pohon,cari);
break;
case 4:
scanf("%d", &del);
hapus(&pohon,del);
break;
case 5:
pohon = NULL;
break;
case 6:
return 0;
default:
getch();
}while(pil!=7);
}
Program Tree dengan 3 operasi dasar (Pre Order , In Order , dan Post Order