data structure (double linked list)
TRANSCRIPT
![Page 1: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/1.jpg)
Double Linked List
Adam M.B.
![Page 2: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/2.jpg)
DEFINITION
![Page 3: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/3.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/4.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/5.jpg)
Example of DeclarationKamus:
Type
point = ↑Simpul
Simpul = Record
< info : char,
prev, next : point >
EndRecord
awal,akhir : point
![Page 6: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/6.jpg)
Operation• Creation• Insertion• Delete• Traversal• Searching• Sorting• Destroy
Same with single linked list
![Page 7: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/7.jpg)
CREATION
![Page 8: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/8.jpg)
ProcessPointer awal and akhir is given nil value.
awal akhir
![Page 9: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/9.jpg)
INSERTION
![Page 10: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/10.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/11.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/12.jpg)
Front Insertion (cont’d)
2 3
baru
1baru↑.next awalawal↑.prev baruawal baru
awal akhir
![Page 13: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/13.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/14.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/15.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/16.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/17.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/18.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/19.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/20.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/21.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/22.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/23.jpg)
DELETION
![Page 24: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/24.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/25.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/26.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/27.jpg)
Front Deletion (cont’d)
awal↑.prev nil dealloc(phapus)
2 4 5 9
Awal Akhir
phapus
![Page 28: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/28.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/29.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/30.jpg)
• 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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/31.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/32.jpg)
Back Deletion (cont’d)
akhir↑.next nil
dealloc(phapus)
2 4 5 9
Awal Akhir phapus
![Page 33: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/33.jpg)
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)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/34.jpg)
• Middle deletion in double linked list is similar as middle deletion in single linked list.
Middle Deletion
![Page 35: Data Structure (Double Linked List)](https://reader038.vdocuments.us/reader038/viewer/2022102811/58cfd6931a28ab13238b4f1b/html5/thumbnails/35.jpg)
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