More Related Content
Similar to Operations on Single Linked Lists Guide
Similar to Operations on Single Linked Lists Guide (20)
Operations on Single Linked Lists Guide
- 1. Operations on Single Linked Lists
Objectives
In this lesson, you will learn to:
Implement the following operations on single linked
list:
Traversing a linked list
Querying information
Deleting nodes
Sorting lists
©NIIT Operations On Single Linked List/Lesson 2/Slide 1 of 9
- 2. Operations on Single Linked Lists
Traversing a Linked List
Helps to display the contents of a list
Is done by following the listed steps:
1. Set a temporary pointer, temp, to START
2. Display the INFO part of the node pointed by temp
3. Advance the pointer, temp, so that it points to the
next node
4. Repeat steps 2 and 3 until temp is not equal to
NULL
©NIIT Operations On Single Linked List/Lesson 2/Slide 2 of 9
- 3. Operations on Single Linked Lists
Problem Statement 2.D.1
Create an application that accepts the names of an
unknown number of customers and displays them in
alphabetical order.
©NIIT Operations On Single Linked List/Lesson 2/Slide 3 of 9
- 4. Operations on Single Linked Lists
Querying Information
Is done by following the listed steps:
1. The pointer CURRENT, is positioned at the node
that contains the name which matches the supplied
string
2. The pointer PRECEDE, is positioned at the node
that is just before the node pointed by CURRENT
3. If the pointer CURRENT contains NULL, it means
that the entire list was traversed without finding the
specified string
©NIIT Operations On Single Linked List/Lesson 2/Slide 4 of 9
- 5. Operations on Single Linked Lists
Deleting Nodes
Can be done in two forms:
Logical deletion of the node from the linked list (de-
linking the node from the list)
Physical deletion of the node to free the memory
occupied by the node (the delete operator used
to free the memory occupied by the node)
©NIIT Operations On Single Linked List/Lesson 2/Slide 5 of 9
- 6. Operations on Single Linked Lists
Deleting Nodes (Contd..)
Is done by following the listed steps:
1. Check whether or not the supplied string is present in
any of the nodes
2. Position the pointer CURRENT at the node to be
deleted
3. Position the pointer PRECEDE at the node that is just
before the node pointed by CURRENT
4. Reposition START if the node that was delinked was
the first node in the list
5. Delete the memory for the CURRENT node
©NIIT Operations On Single Linked List/Lesson 2/Slide 6 of 9
- 7. Operations on Single Linked Lists
Problem Statement 2.D.2
Modify the above application to allow deletion of
unwanted customer records.
©NIIT Operations On Single Linked List/Lesson 2/Slide 7 of 9
- 8. Operations on Single Linked Lists
Problem Statement 2.P.1
Modify the above application such that along with the
name of the customer, his address and customer code is
also stored and on querying the record based on
customer code, the user can view customer details.
©NIIT Operations On Single Linked List/Lesson 2/Slide 8 of 9
- 9. Operations on Single Linked Lists
Summary
To display the contents of the list, you need to
traverse the list.
Linked list can be queried, to display the data stored
in a list.
The deletion of a node can be performed at three
different levels:
At the beginning of the list
In the middle of the list
At the end of the list
©NIIT Operations On Single Linked List/Lesson 2/Slide 9 of 9