LINKED LIST
Linked Lists A Linked List is a linear collection of data elements, called nodes pointing to the next nodes by means of pointers
NEED FOR LINKED LIST Linked List overcome the drawbacks of arrays as in linked list number of elements need not be predetermined, more memory can be allocated or released during the processing as when required ,making insertions and deletions much easier and simpler
TYPES OF LINKED LIST Linked list are of two types:- Singly linked lists: It contains node with single pointer pointing to the next node in sequence Doubly linked list: it contains two pointers, one pointing to previous node and other pointing to the next node in sequence
Singly linked list LIST START 10 20 30 40 Next point of second node Pointer storing the address Of first node Info part
Basic operations on singly linked list Searching Insertion Deletion Traversal Reversal Splitting Concatenation but we will discuss only insertion, deletion and traversal only
Singly linked list Insertion in the beginning of the list 10 20 30 40 New link 5 Represents the status before insertion Insertion in the beginning of the list
Insertion In the beginning of a list Algorithm ptr=START NEWPTR=new node If NEWPTR=NULL Print “no space available ! Aborting !!” Else { NEWPTR INFO=ITEM NEWPTR LINK=NULL If START=NULL then START=NEWPTR Save=START NEWPTR - LINK=save } END
Singly linked list Insertion in the end of the list Previously null 10 20 30 40 New link 50 Insertion in the end of the list
Insertion in the end of list Declare pointers START,PTR,NEWPTR,REAR PTR=START NEWPTR=new node If NEWPTR=NULL Print ”no space available !aborting!!!” Exit ELSE { NEWPTR LINK=NULL} If START=NULL THEN { START=NEWPTR REAR=NEWPTR } REAR LINK = NEWPTR END
DELETION Deletion of item from a linked list involves Search for item in the list If available, make its previous node point to its next node
Singly linked list Deletion of a item from the linked list New link 10 20 30 40 50 ITEM 60 Represents Old links Deletion of a item from the linked list
Deletion from the beginning of list Declare pointers START,ptr If START=NULL then print “underflow” else { Ptr=START START = ptr LINK Delete ptr } end
Traversal It means processing of all the nodes of the list one by one. the following algorithm prints all the elements of it ptr=start Repeat steps (iii) and (iv) until ptr=NULL Print ptr INFO Ptr = ptr LINK end
THANK YOU