Dsa 4
Dsa 4
Aim:
Implement the singly linked list and circular linked list: The expected operations are Insertion
operation at the front of the list, at the back of the list and any position in the list, Deletion of
an element from the list, displaying all elements in the list.
Description:
A linked list is a linear data structure where each element is a separate object. Each element
(we will call it a node) of a list is comprised of two items- the data and a reference to the next
node. The last node has a reference to null. The entry point into a linked list is called the head
of the list. It should be noted that the head is not a separate node, but a reference to the first
node. If the list is empty then the head is a null reference. A linked list is a dynamic data
structure. The number of nodes in a list is not fixed and can grow and shrink on demand. Any
application which has to deal with an unknown number of objects will need to use a linked
list. One disadvantage of a linked list against an array is that it does not allow direct access to
the individual elements. If you want to access a particular item then you have to start at the
head and follow the references until you get to that item. Another disadvantage is that a
linked list uses more memory compared with an array - extra 4 bytes (on 32-bit CPU) to store
a reference to the next node.
Circular Linked list: Circular linked list is a linked list where all nodes are connected to
form a circle. There is no NULL at the end.
Output:
clist = CircularLinkedList()
clist.insert_atend(3)
clist.insert_atend(4)
clist.insert_atend(5)
clist.insert_at_beginning(2)
clist.insert_at_beginning(1)
clist.insert_at_position(5,6)
clist.display()
Output:
Result:
These program successfully demonstrate the implementation of Linked list and Circular
linked list along with various methods like insert_front, insert_end, insert_pos, delete and
display.