Presentation is loading. Please wait.

Presentation is loading. Please wait.

LINKED LIST.

Similar presentations


Presentation on theme: "LINKED LIST."— Presentation transcript:

1 LINKED LIST

2 Linked Lists A Linked List is a linear collection of data elements, called nodes pointing to the next nodes by means of pointers

3 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

4 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

5 Singly linked list LIST START 10 20 30 40 Next point of second node
Pointer storing the address Of first node Info part

6 Basic operations on singly linked list
Searching Insertion Deletion Traversal Reversal Splitting Concatenation but we will discuss only insertion, deletion and traversal only

7 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

8 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

9 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

10 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

11 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

12 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

13 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

14 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

15 THANK YOU


Download ppt "LINKED LIST."

Similar presentations


Ads by Google