Double Linked List
Adam M.B.
DEFINITION

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)
Declaration
Kamus:
Type
nama_pointer = ↑Simpul
Simpul = Record
< medan_data : tipedata,
prev, next : nama_pointer >
EndRecord
nama_var_pointer : nama_pointer
Example of Declaration
Kamus:
Type
point = ↑Simpul
Simpul = Record
< info : char,
prev, next : point >
EndRecord
awal,akhir : point
Operation
• Creation
• Insertion
• Delete
• Traversal
• Searching
• Sorting
• Destroy
Same with
single linked list
CREATION

Process
Pointer awal and akhir is given nil
value.
awal akhir
INSERTION

• If list is empty (awal = nil).
Front Insertion
awal akhir
baru 1
akhir  baru
awal  baru
baru↑.info  1
baru↑.next  nil
baru↑.prev  nil
alloc(baru)
• 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 1
alloc(baru)
baru↑.info  1
baru↑.prev  nil
Front Insertion (cont’d)
2 3
baru 1
baru↑.next  awal
awal↑.prev  baru
awal baru
awal akhir
The last result for front insertion if linked list
wasn’t empty:
Front Insertion (cont’d)
2 3
akhir
1
awalbaru
• If list is empty (awal = nil)  the
process is same as front
insertion if double linked
list is empty.
Back Insertion
• 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 1
alloc(baru)
baru↑.info  1
baru↑.next  nil
New node will be inserted after the node that
was refered by akhir.
Back Insertion (cont’d)
baru
awal
2 3
akhir
1
baru↑.prev  akhir
akhir↑.next  baru
akhir baru
The last result for back insertion if linked list
wasn’t empty:
Back Insertion (cont’d)
baru
2 3
1
awal akhirawal
2 3
akhir
1
• If list is empty (awal = nil)  the
process is same as front
insertion if linked list is
empty.
Middle Insertion
• If list isn’t empty (awal ≠ nil).
Middle Insertion (cont’d)
Node 4 will be inserted before 9:
Awal
5 97
Akhir
10
Awal
5 97
Akhir
10
bantu
Middle Insertion (cont’d)
baru 4
alloc(baru)
baru↑.info  4
baru↑.next  bantubaru↑.prev  bantu↑.prev
Awal
5 97
Akhir
10
bantu
Middle Insertion (cont’d)
bantu↑.prev↑.next  baru
Awal
5 97
Akhir
10
bantu
baru 4
bantu↑.prev  baru
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
DELETION

• Delete one node in beggining of linked list if
linked list has only one node (awal = akhir).
Front Deletion
phapus  awal
Awal
Akhir
2
Awal
Akhir
2
Awal
Akhir
elemen  phapus↑.info
awal  nil
akhir  nil
dealloc(phapus)
menjadi
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  awal
phapus
elemen  phapus↑.info
elemen
Front Deletion (cont’d)
2 4 5 9
Akhir
phapus
awal  awal↑.next atau awal  phapus↑.next
Awal
Front Deletion (cont’d)
awal↑.prev  nildealloc(phapus)
2 4 5 9
Awal Akhir
phapus
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
• 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
• 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
Back Deletion (cont’d)
2 4 5 9
phapus
akhir  akhir↑.prev atau akhir  phapus↑.prev
Awal Akhir
Back Deletion (cont’d)
akhir↑.next  nildealloc(phapus)
2 4 5 9
Awal Akhir phapus
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
• Middle deletion in double linked list is
similar as middle deletion
in single linked list.
Middle Deletion
Contact Person:
Adam Mukharil Bachtiar
Informatics Engineering UNIKOM
Jalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: adfbipotter@gmail.com
Blog: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2012

Data Structure (Double Linked List)

  • 1.
  • 2.
  • 3.
    Linked list thatits node consists of two connection fields (prev and next). Double Linked List Info Field (Info) Right Connection Field (Next) Left Connection Field (Prev)
  • 4.
    Declaration Kamus: Type nama_pointer = ↑Simpul Simpul= Record < medan_data : tipedata, prev, next : nama_pointer > EndRecord nama_var_pointer : nama_pointer
  • 5.
    Example of Declaration Kamus: Type point= ↑Simpul Simpul = Record < info : char, prev, next : point > EndRecord awal,akhir : point
  • 6.
    Operation • Creation • Insertion •Delete • Traversal • Searching • Sorting • Destroy Same with single linked list
  • 7.
  • 8.
    Process Pointer awal andakhir is given nil value. awal akhir
  • 9.
  • 10.
    • If listis empty (awal = nil). Front Insertion awal akhir baru 1 akhir  baru awal  baru baru↑.info  1 baru↑.next  nil baru↑.prev  nil alloc(baru)
  • 11.
    • If listisn’t empty (awal ≠ nil). For example, there is list that has two nodes: Front Insertion (cont’d) awal 2 3 akhir baru 1 alloc(baru) baru↑.info  1 baru↑.prev  nil
  • 12.
    Front Insertion (cont’d) 23 baru 1 baru↑.next  awal awal↑.prev  baru awal baru awal akhir
  • 13.
    The last resultfor front insertion if linked list wasn’t empty: Front Insertion (cont’d) 2 3 akhir 1 awalbaru
  • 14.
    • If listis empty (awal = nil)  the process is same as front insertion if double linked list is empty. Back Insertion
  • 15.
    • If listisn’t empty (awal ≠ nil). For example, there is list that has two nodes: Back Insertion (cont’d) awal 2 3 akhir baru 1 alloc(baru) baru↑.info  1 baru↑.next  nil
  • 16.
    New node willbe inserted after the node that was refered by akhir. Back Insertion (cont’d) baru awal 2 3 akhir 1 baru↑.prev  akhir akhir↑.next  baru akhir baru
  • 17.
    The last resultfor back insertion if linked list wasn’t empty: Back Insertion (cont’d) baru 2 3 1 awal akhirawal 2 3 akhir 1
  • 18.
    • If listis empty (awal = nil)  the process is same as front insertion if linked list is empty. Middle Insertion
  • 19.
    • If listisn’t empty (awal ≠ nil). Middle Insertion (cont’d) Node 4 will be inserted before 9: Awal 5 97 Akhir 10 Awal 5 97 Akhir 10 bantu
  • 20.
    Middle Insertion (cont’d) baru4 alloc(baru) baru↑.info  4 baru↑.next  bantubaru↑.prev  bantu↑.prev Awal 5 97 Akhir 10 bantu
  • 21.
    Middle Insertion (cont’d) bantu↑.prev↑.next baru Awal 5 97 Akhir 10 bantu baru 4 bantu↑.prev  baru
  • 22.
    The last resultfor 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
  • 23.
  • 24.
    • Delete onenode in beggining of linked list if linked list has only one node (awal = akhir). Front Deletion phapus  awal Awal Akhir 2 Awal Akhir 2 Awal Akhir elemen  phapus↑.info awal  nil akhir  nil dealloc(phapus) menjadi
  • 25.
    If deletion happensin linked list with one node then linked list will be empty. Front Deletion (cont’d) 2 4 5 9 Awal Akhir phapus  awal phapus elemen  phapus↑.info elemen
  • 26.
    Front Deletion (cont’d) 24 5 9 Akhir phapus awal  awal↑.next atau awal  phapus↑.next Awal
  • 27.
    Front Deletion (cont’d) awal↑.prev nildealloc(phapus) 2 4 5 9 Awal Akhir phapus
  • 28.
    The last resultfor 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
  • 29.
    • Delete onenode 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
  • 30.
    • If linkedlist 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
  • 31.
    Back Deletion (cont’d) 24 5 9 phapus akhir  akhir↑.prev atau akhir  phapus↑.prev Awal Akhir
  • 32.
    Back Deletion (cont’d) akhir↑.next nildealloc(phapus) 2 4 5 9 Awal Akhir phapus
  • 33.
    The last resultfor back deletion if linked list has more than one node: Back Deletion (cont’d) 2 4 5 9 Awal Akhir phapus
  • 34.
    • Middle deletionin double linked list is similar as middle deletion in single linked list. Middle Deletion
  • 35.
    Contact Person: Adam MukharilBachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2012