Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2

3

4 Traversing a Linked List

5 Searching A Linked List a) List is Unsorted

6 b) List is Sorted

7

8

9

10 Insertion Algorithms

11

12 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

13 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

14 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

15 Header node


Download ppt "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."

Similar presentations


Ads by Google