1 / 13

DLL

DLL. Doubly Linked List. prev. next. A doubly linked list provides a natural implementation of the List ADT Nodes implement Position and store: element link to the previous node link to the next node Special trailer and header nodes. elem. node. trailer. nodes/positions. header.

lucy-burt
Download Presentation

DLL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DLL

  2. Doubly Linked List prev next • A doubly linked list provides a natural implementation of the List ADT • Nodes implement Position and store: • element • link to the previous node • link to the next node • Special trailer and header nodes elem node trailer nodes/positions header elements Linked Lists

  3. Insertion • We visualize operation insertAfter(p, X), which returns position q p A B C p q A B C X p q A B X C Linked Lists

  4. Insertion Algorithm Algorithm insertAfter(p,e): Create a new node v v.setElement(e) v.setPrev(p) {link v to its predecessor} v.setNext(p.getNext()) {link v to its successor} (p.getNext()).setPrev(v) {link p’s old successor to v} p.setNext(v) {link p to its new successor, v} return v {the position for the element e} Linked Lists

  5. p A B C D Deletion • We visualize remove(p), where p = last() A B C p D A B C Linked Lists

  6. Deletion Algorithm Algorithm remove(p): t = p.element {a temporary variable to hold the return value} (p.getPrev()).setNext(p.getNext()) {linking out p} (p.getNext()).setPrev(p.getPrev()) p.setPrev(null) {invalidating the position p} p.setNext(null) return t Linked Lists

  7. Implemnetasi

  8. ADT DLL class NodeDLL{ int data; NodeDLLprev,next; } public class DoubleLinkedList { private NodeDLLpKepala, pEkor; public DoubleLinkedList(){pKepala= null; pEkor= null;} public void sisipDipKepala(intdt){} public void sisipDipEkor(int data){} public void cetak(String kom){} public void hapusDataTertentu(intdataHapus){} public void sisipDataTerurut(int data){} }

  9. DLL.sisipDipKepala public void sisipDipKepala(intdt){ NodeDLLbaru = new NodeDLL(); baru.data = dt; if (pKepala == null) { baru.prev = pKepala; baru.next = pEkor; pKepala = baru; pEkor = baru; } else { baru.next = pKepala; pKepala.prev = baru; pKepala = baru; baru.prev = pKepala; } }

  10. DLL.sisipDipEkor public void sisipDipEkor(int data){ NodeDLLbaru = new NodeDLL(); baru.data = data; if (pEkor == null) { baru.prev = pKepala; baru.next = pEkor; pKepala = baru; pEkor = baru; } else { baru.prev = pEkor; pEkor.next = baru; pEkor = baru; baru.next = pEkor; } }

  11. DLL.cetak public void cetak(String kom){ System.out.println(kom); NodeDLL p = pKepala; while (p!=pEkor.next){ System.out.print(p.data+"->"); p = p.next; } System.out.println(); }

  12. Diskusi public void hapusDataTertentu(intdataHapus){ ??? } public void sisipDataTerurut(int data){ ??? }

  13. TugasKelompok k-2 • Suatuangkatanmahasiswaterdiridaribeberapamahasiswa, setiapmahasiswapadasuatu semester 3 keatasdapatmengambilbeberapamatakuliah yang tidaksamaantarasatumahasiswadenganmahasiswa yang lain. Susun ADT persoalaninimenggunakan DLL. • Contoh • Angkatan : 2011 Semester : 3 • Jumlahmhs : 5 IP Rata-rata : .. • DaftarMhs • 1. Ali 011000011 2 3 • SBD B 3 • ASD B 5 2. Toni 0110000012 1 3.5 SO B+ 3 3 … DikumpulkanMinggudepantgl 27 Maret 2013 (HC) • Kembangkan SC (dapatdidownloaddi e-learning) Dikumpulksndi Recording (SebelumPulang)

More Related