slide1
Download
Skip this Video
Download Presentation
DLL

Loading in 2 Seconds...

play fullscreen
1 / 13

DLL - PowerPoint PPT Presentation


  • 134 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' DLL' - lucy-burt


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
doubly linked list
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

insertion
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

insertion algorithm
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

deletion

p

A

B

C

D

Deletion
  • We visualize remove(p), where p = last()

A

B

C

p

D

A

B

C

Linked Lists

deletion algorithm
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

adt dll
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){}

}

dll sisipdipkepala
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;

}

}

dll sisipdipekor
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;

}

}

dll cetak
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();

}

diskusi
Diskusi

public void hapusDataTertentu(intdataHapus){

???

}

public void sisipDataTerurut(int data){

???

}

tugas kelompok k 2
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)

ad