35
Double Linked List Adam M.B.

Data Structure (Double Linked List)

Embed Size (px)

Citation preview

Page 1: Data Structure (Double Linked List)

Double Linked List

Adam M.B.

Page 2: Data Structure (Double Linked List)

DEFINITION

Page 3: Data Structure (Double Linked List)

Linked list that its node consists of two

connection fields (prev and next).

Double Linked List

Info Field (Info)

Right Connection Field (Next)

Left Connection Field (Prev)

Page 4: Data Structure (Double Linked List)

DeclarationKamus:

Type

nama_pointer = ↑Simpul

Simpul = Record

< medan_data : tipedata,

prev, next : nama_pointer >

EndRecord

nama_var_pointer : nama_pointer 

Page 5: Data Structure (Double Linked List)

Example of DeclarationKamus:

Type

point = ↑Simpul

Simpul = Record

< info : char,

prev, next : point >

EndRecord

awal,akhir : point 

Page 6: Data Structure (Double Linked List)

Operation• Creation• Insertion• Delete• Traversal• Searching• Sorting• Destroy

Same with single linked list

Page 7: Data Structure (Double Linked List)

CREATION

Page 8: Data Structure (Double Linked List)

ProcessPointer awal and akhir is given nil value.

awal akhir

Page 9: Data Structure (Double Linked List)

INSERTION

Page 10: Data Structure (Double Linked List)

• If list is empty (awal = nil).

Front Insertion

awal

akhir

baru

1

akhir baru

awal baru

baru↑.info 1baru↑.next nilbaru↑.prev nil

alloc(baru)

Page 11: Data Structure (Double Linked List)

• If list isn’t empty (awal ≠ nil). For example, there is list that has two nodes:

Front Insertion (cont’d)

awal

2 3

akhir

baru 1alloc(baru)baru↑.info 1baru↑.prev nil

Page 12: Data Structure (Double Linked List)

Front Insertion (cont’d)

2 3

baru

1baru↑.next awalawal↑.prev baruawal baru

awal akhir

Page 13: Data Structure (Double Linked List)

The last result for front insertion if linked list wasn’t empty:

Front Insertion (cont’d)

2 3

akhir

1

awal

baru

Page 14: Data Structure (Double Linked List)

• If list is empty (awal = nil) the

process is same as front insertion if double linked list is empty.

Back Insertion

Page 15: Data Structure (Double Linked List)

• If list isn’t empty (awal ≠ nil). For example, there is list that has two nodes:

Back Insertion (cont’d)

awal

2 3

akhir

baru

1alloc(baru)baru↑.info 1baru↑.next nil

Page 16: Data Structure (Double Linked List)

New node will be inserted after the node that was refered by akhir.

Back Insertion (cont’d)

baru

awal

2 3

akhir

1baru↑.prev akhirakhir↑.next baruakhir baru

Page 17: Data Structure (Double Linked List)

The last result for back insertion if linked list wasn’t empty:

Back Insertion (cont’d)

baru

2 3

1

awal akhir

awal

2 3

akhir

1

Page 18: Data Structure (Double Linked List)

• If list is empty (awal = nil) the

process is same as front insertion if linked list is empty.

Middle Insertion

Page 19: Data Structure (Double Linked List)

• If list isn’t empty (awal ≠ nil).

Middle Insertion (cont’d)

Node 4 will be inserted before 9:

Awal5 97

Akhir

10

Awal

5 97

Akhir

10

bantu

Page 20: Data Structure (Double Linked List)

Middle Insertion (cont’d)

baru

4alloc(baru)baru↑.info 4

baru↑.next bantu

baru↑.prev bantu↑.prev

Awal

5 97

Akhir

10

bantu

Page 21: Data Structure (Double Linked List)

Middle Insertion (cont’d)

bantu↑.prev↑.next baru

Awal

5 97

Akhir

10

bantu

baru 4

bantu↑.prev baru

Page 22: Data Structure (Double Linked List)

The last result for middle insertion if linked list wasn’t empty:

Middle Insertion (cont’d)

Awal

5 97

Akhir

104

baru

4

Awal

5 97

Akhir

10

bantu

Page 23: Data Structure (Double Linked List)

DELETION

Page 24: Data Structure (Double Linked List)

• Delete one node in beggining of linked list if linked list has only one node (awal = akhir).

Front Deletion

phapus awal

AwalAkhir

2

AwalAkhir

2

Awal

Akhir

elemen phapus↑.infoawal nilakhir nil

dealloc(phapus)

menjadi

Page 25: Data Structure (Double Linked List)

If deletion happens in linked list with one node then linked list will be empty.

Front Deletion (cont’d)

2 4 5 9

Awal Akhir

phapus awalphapus

elemen phapus↑.info

elemen

Page 26: Data Structure (Double Linked List)

Front Deletion (cont’d)

2 4 5 9

Akhir

phapus

awal awal↑.next atau awal phapus↑.next

Awal

Page 27: Data Structure (Double Linked List)

Front Deletion (cont’d)

awal↑.prev nil dealloc(phapus)

2 4 5 9

Awal Akhir

phapus

Page 28: Data Structure (Double Linked List)

The last result for front deletion if linked list has more than one node:

Front Deletion (cont’d)

4 5 9

Awal Akhir

4 5 9

Akhir

phapus

2

Awal

Page 29: Data Structure (Double Linked List)

• Delete one node in back of linked list if linked list has only one node (awal =

akhir). This process is same as front deletion if linked list has only one node.

Back Deletion

Page 30: Data Structure (Double Linked List)

• If linked list has more than one node (awal ≠ akhir). For example, linked list has four nodes.

Back Deletion (cont’d)

2 4 5 9

Awal Akhir

phapus akhir

phapus

elemen phapus↑.info

elemen

Page 31: Data Structure (Double Linked List)

Back Deletion (cont’d)

2 4 5 9

phapus

akhir akhir↑.prev atau akhir phapus↑.prev

Awal Akhir

Page 32: Data Structure (Double Linked List)

Back Deletion (cont’d)

akhir↑.next nil

dealloc(phapus)

2 4 5 9

Awal Akhir phapus

Page 33: Data Structure (Double Linked List)

The last result for back deletion if linked list has more than one node:

Back Deletion (cont’d)

2 4 5 9

Awal Akhir

phapus

Page 34: Data Structure (Double Linked List)

• Middle deletion in double linked list is similar as middle deletion in single linked list.

Middle Deletion

Page 35: Data Structure (Double Linked List)

Contact Person:Adam Mukharil Bachtiar

Informatics Engineering UNIKOMJalan Dipati Ukur Nomor. 112-114 Bandung 40132

Email: [email protected]: http://adfbipotter.wordpress.com

Copyright © Adam Mukharil Bachtiar 2012

GRACIASTHANK YOU