Exp4 RAI DSA SLL 24-25
Exp4 RAI DSA SLL 24-25
Experiment No. : 4
Aim: Implementing Singly Linked List (SLL) supporting following operations using
menu driven program.
1. Insert at the Begin
2. Insert after the specified existing node
3. Delete before the specified existing node
4. Display all elements in tabular form.
__________________________________________________________________________________
__________________________________________________________________________________
Theory:
A linked list is a linear data structure where each element is a separate object.
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 compare with an array -
we need extra 4 bytes (on 32-bit CPU) to store a reference to the next node.
Algorithm:
Program should implement the specified operations in the following manner. Also
implement a support method isempty() and make use of it at appropriate places.
1. typdef createSLL() – This function should create a START/HEAD pointer with NULL
value as empty SLL and return the pointer.
2. insertBegin( typedef HEAD, typedef newelement ) – This void function should take a
newelement as an argument to be inserted on an existing SLL and insert it before the element
pointed by the START/HEAD pointer.
3. insertAfter( Typedef HEAD, typedef newelement, typedef existingelement) – This void
function should take newelement and existingelement (after which new has to be inserted) as
arguments. The function should search for an existingelement on non-empty SLL and insert
newelement after this element.
4. typedef deleteBefore(Typedef HEAD, typedef existingelement ) – This function should
search for the existing element passed to the function in the non-empty SLL, delete the node
siting before it and return the deleted element.
5. display(Typedef HEAD ) – This is a void function which should go through non- empty
SLL starting from START/HEAD pointer and display each element of the SLL till the end.
___________________________________________________________________________
Output :
___________________________________________________________________________
Conclusion :
__________________________________________________________________________
__________________________________________________________________________
Grade: AA / AB / BB / BC / CC / CD /DD
References: