Circular Linked List
Adam M.B.
DEFINITION

Linked list that hasn’t null (nil) value in its
connection field.
Circular Linked List
2 4 5 9
Awal Akhir
2 4 5 9
Awal Akhir
Circular Single Linked list
Circular Double Linked list
Operation
• Creation
• Insertion
• Delete
• Traversal
• Searching
• Sorting
• Destroy
Same with linear single
or double linked list
INSERTION

• If list is empty (awal = nil).
Front Insertion
awal akhir
baru 1
akhir  baru
awal  baru
baru↑.info  1
baru↑.next  baru
alloc(baru)
• If list isn’t empty (awal ≠ nil). For example,
there is list that has two nodes:
Front Insertion (cont’d)
baru 1
alloc(baru)
baru↑.info  1
akhirawal
2 3
Front Insertion (cont’d)
baru 1
baru↑.next  awal
akhirawal
2 3
Front Insertion (cont’d)
awal  baru
baru 1
akhirawal
2 3
Front Insertion (cont’d)
baru
1
akhirawal
2 3
akhir↑.next  awal
The last result for front insertion if linked list
wasn’t empty:
Front Insertion (cont’d)
baru
1
akhirawal
2 3
• If list is empty (awal = nil)  the
process is same as front
insertion if 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)
akhirawal
2 3
New node will be inserted after the node that
was refered by akhir.
Back Insertion (cont’d)
baru 1
alloc(baru)
baru↑.info  1
Back Insertion (cont’d)
baru 1
akhir↑.next baru
akhirawal
2 3
Back Insertion (cont’d)
akhir  baru
akhirawal
3 2
baru 1
akhir↑.next awal
The last result for back insertion if linked list
wasn’t empty:
Back Insertion (cont’d)
akhirawal
3 2
baru
1
Circular linked list doesn’t give effect for
middle insertion. The algorithm is same as
middle insertion in linear single or double
linked list (depend on implementation of
circular linked list).
Middle Insertion
DELETION

• Delete one node in beggining of linked list if
linked list has only one node (awal = akhir).
Front Deletion
awal akhir
1 THEN
elemen
phapus
phapus  awal elemen  phapus↑.info
awal  nil
awal
akhir
akhir  nil
dealloc(phapus)
• If linked list has more than one node (awal ≠
akhir). For example, linked list has two
nodes.
Front Deletion (cont’d)
akhirawal
2 3
Front Deletion (cont’d)
akhirawal
2 3
phapus  awal
phapus
elemen
elemen  phapus↑.info
awal  awal↑.next
akhir↑.next  awal
dealloc(phapus)
The last result for front deletion if linked list has
more than one node:
Front Deletion (cont’d)
akhirawal
2 3phapus
elemen
• 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)
akhir
3
awal
1 42
Back Deletion (cont’d)
akhir
phapus  awal
phapus
elemen
elemen  akhir↑.info akhir  phapus
akhir↑.next  awal
dealloc(phapus)
3
awal
1 42
phapus
phapus  phapus↑.nextwhile (phapus↑.next ≠ akhir)
do
phapus  phapus↑.next
endwhile
The last result for back deletion if linked list has
more than one node:
Back Deletion (cont’d)
akhirphapus
elemen
3
awal
1 42
phapus
Other operations of circular linked list are same
as linear single or double linked list but be
careful of overlooping (endless looping)because
there aren’t null value in its connection fields.
Other Operation
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 (Circular Linked List)

  • 1.
  • 2.
  • 3.
    Linked list thathasn’t null (nil) value in its connection field. Circular Linked List 2 4 5 9 Awal Akhir 2 4 5 9 Awal Akhir Circular Single Linked list Circular Double Linked list
  • 4.
    Operation • Creation • Insertion •Delete • Traversal • Searching • Sorting • Destroy Same with linear single or double linked list
  • 5.
  • 6.
    • If listis empty (awal = nil). Front Insertion awal akhir baru 1 akhir  baru awal  baru baru↑.info  1 baru↑.next  baru alloc(baru)
  • 7.
    • If listisn’t empty (awal ≠ nil). For example, there is list that has two nodes: Front Insertion (cont’d) baru 1 alloc(baru) baru↑.info  1 akhirawal 2 3
  • 8.
    Front Insertion (cont’d) baru1 baru↑.next  awal akhirawal 2 3
  • 9.
    Front Insertion (cont’d) awal baru baru 1 akhirawal 2 3
  • 10.
  • 11.
    The last resultfor front insertion if linked list wasn’t empty: Front Insertion (cont’d) baru 1 akhirawal 2 3
  • 12.
    • If listis empty (awal = nil)  the process is same as front insertion if linked list is empty. Back Insertion
  • 13.
    • If listisn’t empty (awal ≠ nil). For example, there is list that has two nodes: Back Insertion (cont’d) akhirawal 2 3
  • 14.
    New node willbe inserted after the node that was refered by akhir. Back Insertion (cont’d) baru 1 alloc(baru) baru↑.info  1
  • 15.
    Back Insertion (cont’d) baru1 akhir↑.next baru akhirawal 2 3
  • 16.
    Back Insertion (cont’d) akhir baru akhirawal 3 2 baru 1 akhir↑.next awal
  • 17.
    The last resultfor back insertion if linked list wasn’t empty: Back Insertion (cont’d) akhirawal 3 2 baru 1
  • 18.
    Circular linked listdoesn’t give effect for middle insertion. The algorithm is same as middle insertion in linear single or double linked list (depend on implementation of circular linked list). Middle Insertion
  • 19.
  • 20.
    • Delete onenode in beggining of linked list if linked list has only one node (awal = akhir). Front Deletion awal akhir 1 THEN elemen phapus phapus  awal elemen  phapus↑.info awal  nil awal akhir akhir  nil dealloc(phapus)
  • 21.
    • If linkedlist has more than one node (awal ≠ akhir). For example, linked list has two nodes. Front Deletion (cont’d) akhirawal 2 3
  • 22.
    Front Deletion (cont’d) akhirawal 23 phapus  awal phapus elemen elemen  phapus↑.info awal  awal↑.next akhir↑.next  awal dealloc(phapus)
  • 23.
    The last resultfor front deletion if linked list has more than one node: Front Deletion (cont’d) akhirawal 2 3phapus elemen
  • 24.
    • 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
  • 25.
    • If linkedlist has more than one node (awal ≠ akhir). For example, linked list has four nodes. Back Deletion (cont’d) akhir 3 awal 1 42
  • 26.
    Back Deletion (cont’d) akhir phapus awal phapus elemen elemen  akhir↑.info akhir  phapus akhir↑.next  awal dealloc(phapus) 3 awal 1 42 phapus phapus  phapus↑.nextwhile (phapus↑.next ≠ akhir) do phapus  phapus↑.next endwhile
  • 27.
    The last resultfor back deletion if linked list has more than one node: Back Deletion (cont’d) akhirphapus elemen 3 awal 1 42 phapus
  • 28.
    Other operations ofcircular linked list are same as linear single or double linked list but be careful of overlooping (endless looping)because there aren’t null value in its connection fields. Other Operation
  • 29.
    Contact Person: Adam MukharilBachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: [email protected] Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2012