Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <iostream>
- 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 Sdah 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);
- }
- }
- int main()
- {
- int pil,data;
- Node *pohon;
- pohon = NULL;
- do
- {
- system("cls");
- printf("\t#PROGRAM Tree#");
- printf("1.tambah\n");
- printf("2.lihat pre\n");
- printf("3.lihat in\n");
- printf("4.lihat post-order\n");
- printf("5.exit\n");
- printf("Pilihan :");
- scanf("&d",&pil);
- switch(pil)
- {
- case 1:
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement