data structure (circular linked list)
TRANSCRIPT
Chapter 7 - Circular Linked List
Circular Linked List
Adam M.B.
DEFINITION
Linked list that hasnt null (nil) value in its connection field.
Circular Linked List
Circular Single Linked list
Circular Double Linked list
OperationCreationInsertionDeleteTraversalSearchingSortingDestroy
Same with linear single or double linked list
INSERTION
If list is empty (awal = nil).
Front Insertionawalakhir
baru1 akhir baruawal barubaru.info 1baru.next barualloc(baru)
If list isnt empty (awal nil). For example, there is list that has two nodes:
Front Insertion (contd)
baru1alloc(baru)baru.info 1akhir
awal
23
Front Insertion (contd)
baru1baru.next awalakhir
awal
23
Front Insertion (contd)awal baru
baru1akhir
awal
23
Front Insertion (contd)
baru1akhir
awal
23akhir.next awal
The last result for front insertion if linked list wasnt empty:
Front Insertion (contd)
baru1akhir
awal
23
If list is empty (awal = nil) the process is same as front insertion if linked list is empty.
Back Insertion
If list isnt empty (awal nil). For example, there is list that has two nodes:
Back Insertion (contd)akhir
awal
23
New node will be inserted after the node that was refered by akhir.
Back Insertion (contd)
baru1alloc(baru)baru.info 1
Back Insertion (contd)
baru1akhir.next baruakhir
awal
23
Back Insertion (contd)akhir baruakhir
awal
32
baru1akhir.next awal
The last result for back insertion if linked list wasnt empty:
Back Insertion (contd)akhir
awal
32
baru1
Circular linked list doesnt 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
awalakhir
1 THENelemenphapusphapus awalelemen phapus.info awal nil
awal
akhirakhir nildealloc(phapus)
If linked list has more than one node (awal akhir). For example, linked list has two nodes.
Front Deletion (contd)akhir
awal
23
Front Deletion (contd)
akhir
awal
23phapus awalphapuselemenelemen 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 (contd)akhir
awal
23phapuselemen
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 (contd)akhir
3
awal
14
2
Back Deletion (contd)
akhirphapus awalphapuselemenelemen akhir.info akhir phapus akhir.next awal dealloc(phapus)
3
awal
14
2phapusphapus phapus.nextwhile (phapus.next akhir) do phapus phapus.nextendwhile
The last result for back deletion if linked list has more than one node:
Back Deletion (contd)akhirphapuselemen
3
awal
14
2phapus
Other operations of circular linked list are same as linear single or double linked list but be careful of overlooping (endless looping)because there arent null value in its connection fields.
Other Operation
Contact Person:Adam Mukharil BachtiarInformatics Engineering UNIKOMJalan Dipati Ukur Nomor. 112-114 Bandung 40132Email: [email protected]: http://adfbipotter.wordpress.com
Copyright Adam Mukharil Bachtiar 2012GRACIASTHANK YOU
29
2
5
4
9
Awal
Akhir
2
5
4
9
Awal
Akhir