371858253-RizkyMuhammad-145150200111085-F-10.pdf - LAPORAN PRAKTIKUM ALGORITMA DAN STRUKTUR DATA PROGRAM TEKNOLOGI INFORMASI DAN ILMU KOMPUTER

371858253-RizkyMuhammad-145150200111085-F-10.pdf - LAPORAN...

This preview shows page 1 - 4 out of 19 pages.

LAPORAN PRAKTIKUM ALGORITMA DAN STRUKTUR DATA PROGRAM TEKNOLOGI INFORMASI DAN ILMU KOMPUTER UNIVERSITAS BRAWIJAYA BAB : AVL TREE NAMA : RIZKY MUHAMMAD NIM : 145150200111085 TANGGAL : 02/12/2015 ASISTEN : - DWI NOVI SETIAWAN -MUHAMMAD SYAFIQ A. DEFINISI MASALAH 1. Tambahkan method untuk menghapus suatu node pada pohon AVL 2. Dalam proses penyisipan data ke dalam pohon AVL jika kondisi pohon tidak seimbang maka harus dilakukan rotas kiri, rotasi kanan, rotasi kiri kana, atau rotasi kanan dan kiri. Dari program di atas pada baris berapakah dilakukan masing-masing proses ini? 3. Perbaikilah program di pada latihan 10.1 di atas menjadi sub-sub program dengan menambahkan sub program putarKiri, putarKanan, putarKiriKanan, putarKananKiri. B. SOURCE CODE Node.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 package latihan_Bab10; public class Node { int data; int tinggi; Node pKiri; Node pKanan; Node pInduk; public Node ( int data, int tinggi, Node kiri, Node kanan, Node induk) { // TODO Auto-generated constructor stub this .data=data; this .tinggi=tinggi; this .pKiri=kiri; this .pKanan=kanan; this .pInduk=induk; } } AVLT1.java 1 2 3 4 5 6 7 package latihan_Bab10; public class AVLT1 { private Node root; public AVLT1 (){root = null ;} //cari dt di tree, mengembalikan true jika ditemukan //dan false jika tidak public void hapusNode ( int dt) {
Image of page 1

Subscribe to view the full document.

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 int sim =0; int run =0; Node del = root; while (run==0){ if (dt == del.data){ if (del.pInduk== null ){ hapusRoot(del); } else { hapusNode(del, sim); } run=1; } else if (dt < del.data){ del = del.pKiri; sim=0; } else { del = del.pKanan; sim=1; } } } public void hapusRoot (Node del) { if (del.pKanan!= null ){ if (del.pKanan.pKiri== null ){ del.pKanan.pKiri=del.pKiri; } else { Node temp1 = del.pKanan.pKiri; del.pKanan.pKiri= null ; while (temp1.pKiri!= null ){ temp1=temp1.pKiri; } if (temp1.pKanan!= null ){ Node temp1k = temp1.pKanan; temp1.pKanan=del.pKanan; temp1.pKiri=del.pKiri; temp1.pInduk.pKanan=temp1k; root=temp1; } else { temp1.pKanan=del.pKanan; temp1.pKiri=del.pKiri; root=temp1; } } } else { root=del.pKiri; } } public void hapusNode (Node del, int sim) { if (del.pKanan!= null ){ if (del.pKanan.pKiri== null ){ if (sim==0){ del.pInduk.pKiri=del.pKanan; } else if (sim==1){
Image of page 2
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 del.pInduk.pKanan=del.pKanan; } } else { Node temp1 = del.pKanan.pKiri; del.pKanan.pKiri= null ; while (temp1.pKiri!= null ){ temp1=temp1.pKiri; } if (temp1.pKanan!= null ){ Node temp1k =temp1.pKanan; temp1.pKanan=del.pKanan; temp1.pKiri=del.pKiri; temp1.pInduk.pKanan=temp1k; if (sim==0){ del.pInduk.pKiri=temp1; } else if (sim==1){ del.pInduk.pKanan=temp1; } } else { temp1.pKanan=del.pKanan; temp1.pKiri=del.pKiri; if (sim==0){ del.pInduk.pKiri=temp1; } else { del.pInduk.pKanan=temp1; } } } } else { if (sim==0){ del.pInduk.pKiri=del.pKiri; } else if (sim==1){ del.pInduk.pKanan=del.pKiri; } } } public boolean cariDt ( int dt){ Node temp = root; while (temp != null ){ if (dt == temp.data) return true ; //cariDt subtree pKiri else if (dt < temp.data) temp = temp.pKiri; //cariDt subtree pKanan else temp = temp.pKanan; } //dt tidak ditemukan return false ; } //sisip dt ke dalam tree, returns true if berhasil,
Image of page 3

Subscribe to view the full document.

Image of page 4
  • Spring '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes