Materi Kuliah Teknik Informatika

Contoh Source Code Program Java Tree

Assalamualiku..
bagi yang masih bingung dengan tree sebaiknya baca lagi deh contoh dan penjelasan program java tree
mudah mudahan paham,, kalo mau di pelajari insya allah bisa, semangat ngoding jangan menyerah kawan,,
ini output dari sorcode dibawah
baca lagi yg diatas supaya paham maksud outputnya tu gan,,




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Tree;

/**
 *
 * @author Administrator
 */
public class tre {
    public static void main(String[] args) {
        new tre().run();
        
    }
    static class Node{
        Node left;
        Node right;
        int value;
        public Node(int value){
            this.value = value;
        }
        
    }
    public void run(){
        //build the simple tree from chapter 11
        Node root = new Node(5);
        System.out.println("Contoh Binary tree ");
        System.out.println("Membangun tree dengan nilai root");
        insert(root,2);
        insert(root,4);
        insert(root,6);
        insert(root,8);
        insert(root,10);
        insert(root,3);
        insert(root,1);
        System.out.println("Traversing Tree in order ");
        printlnOrder(root);
        System.out.println("Traversing tree front-to-back from location 7");
        printFrontToBack(root, 7);    
    }
    
    public void insert (Node node, int value){
        if(valuenode.value){
            if(node.right!=null) {
                insert(node.right,value);
                
            }
            else{
                System.out.println("Dimasukkan "+ value +" ke kanan dari "+node.value);
                node.right = new Node(value);
            }
        }
    }
     
    public void printlnOrder(Node node){
        if (node!=null){
            printlnOrder(node.left);
            System.out.println("Di lalui "+ node.value);
            printlnOrder(node.right);
        }
    }
    
    public void printFrontToBack(Node node, int camera){
        if (node == null){
            return;
            if(node.value>camera){
                //print in order
                printFrontToBack(node.left, camera);
                System.out.println("Dilalui "+ node.value);
                printFrontToBack(node.right, camera);
                
            }
            else if(node.value
0 Komentar untuk "Contoh Source Code Program Java Tree"

Back To Top -->