Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 10

Linked Lists

Terminology for Lists


 List: A collection of data whose entries are
arranged sequentially. It refers to a linear
collection of data items.
 Head: The beginning of the list
 Tail: The end of the list
Linked Lists
 One-way list, is a linear collection of data
elements, called nodes, where the linear
order is given by means of pointers.
 Each node is divided into two parts: -
 1st part contains the information of the element
 2nd part contains the address of the next node in
the list (link field/next pointer field)
 The pointer of the last node contains a special
value  null pointer (which is any invalid address)
Structure of Linked List
Linked Lists

A B C 
Head
 A linked list is a series of connected nodes
 Each node contains at least
 A piece of data (any type)
 Pointer to the next node in the list
 Head: pointer to the first node node
 The last node points to NULL A
data pointer
Representation of LL in
Memory
 Let LIST be a linked list. It will be maintained
in memory.
 It requires two linear arrays  INFO[K] & LINK[K]
 It requires a variable name  START &
 It requires a nextpointer sentinel  NULL
Example
INFO LINK
1 start from 9 to Null = 0
9
2
3 O 6
4 T 0
5
6 11
7 X 10
8
9 N 3
10 I 4
11 E 7
12
Traversing a LL
 Traversing algo uses a pointer variable PTR which
points to the node i.e. currently being processed.
LINK[PTR] points to the next node to be processed.
PTR := LINK [PTR]

A B C 
Algorithm
 TRAVERSE(LIST, PTR, PROCESS)
1.Set PTR := START. [Initializes pointer PTR.]
2. Repeat Steps 3 & 4 while PTR != NULL.
3. Apply PROCESS to INFO[PTR].
4. Set PTR := LINK[PTR].
[PTR now points to the next node.]
[End of Step 2 loop.]
5. Exit.
Thank You!!!

You might also like