Linked Lists A linked list or one way list is a linear collection of data elements called nodes where the order is given by means of pointers It is divided into 2 parts: The first part contains the information of elements Second part contains link field or next pointer field which stores the address of next node in the list
Traversing a Linked List
Searching A Linked List a) List is Unsorted
b) List is Sorted
Insertion Algorithms
INSERTING INTO A SORTED LINKED LIST [LIST IS EMPTY] IF START =NULL THEN:SET LOC:=NULL AND RETURN [SPECIAL CASE] IF ITEM<INFO[START],THEN:SET LOC:=NULL AND RETURN SET SAVE:=START AND PTR:=LINK[START] [INTIALIZE POINTER] REPEAT STEPS 5 AND 6 WHILE PTR!=NULL IF ITEM<INFO[PTR],THEN SET LOC:=SAVE & RETURN SET LOC:=SAVE AND RETURN SET SAVE:=PTR AND PTR:=LINK[PTR] SET LOC:=SAVE RETURN
Inserting after a Given Node [overflow] IF AVAIL=NULL , then : WRITE:OVERFLOW,AND EXIT. [removes first node from AVAIL list] SET NEW:=AVAIL AND AVAIL:=LINK[AVAIL] SET INFO[NEW]:=ITEM [copies new data into new node] IF LOC=NULL,THEN:[INSERT AS FIRST NODE] SET LINK[NEW]:=START AND START:=NEW ELSE:[insert after node with location LOC] SET LINK[NEW]:=LINK[LOC] AND LINK[LOC]:=NEW EXIT
HEADER LINKED LISTS A header linked list which always contain a special node called header node at the beginning of the list. There are two kinds of widely used header lists: Grounded header list is a header list where the last node contains null pointer Circular header list is a header list where the last node points back to the header node
Header node