Professional Documents
Culture Documents
PROGRAM 1
Program 1 ini membuat binaru tree.
Hasil program jika dituliskan dalam bentuk tree.
Bentuk tree dari hasil program yaitu tree yang berbentuk horizontal.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define COUNT 10
// Driver code
int main()
{
Node *root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
print2D(root);
_getch();
}
PROGRAM 2
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
return(Node);
}
/* Driver code*/
int main()
{
node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
PROGRAM 3
Program 3 ini untuk menghitung ketinggian tree.
Gambar di bawah ini mempunyai ketinggian 3. Untuk node root tidak dihitung.
// ProgTree4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
// Driver code
int main()
{
node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
PROGRAM 4
Program 4 ini menampilkan data dari gambar di bawah ini berdasarkan inorder, preorder, dan
postorder :
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
_getch();
}