Click here to load reader
Upload
raj-agrawal
View
95
Download
0
Embed Size (px)
Citation preview
Data Structure
1
Data Structures: A Pseudocode Approach with C 1
General linear lists
A general linear list is a list in which operations can be done anywhere in the list.
For simplicity, we refer to general linear lists as lists.
Data Structures: A Pseudocode Approach with C 2
5-1 Basic Operations
We begin with a discussion of the basic list operations. Each
operation is developed using before and after figures to show the
changes.
• Insertion
• Deletion
• Retrieval
• Traversal
Data Structures: A Pseudocode Approach with C 3
insertion
Insertion is used to add a new element to the list
Data Structures: A Pseudocode Approach with C 4
deletion
Deletion is used to remove an element from the list.
Data Structures: A Pseudocode Approach with C 5
retrieval
Retrieval is used to get the information related to an element
without changing the structure of the list.
Data Structures: A Pseudocode Approach with C 6
traversal
List traversal processes each element in a list in sequence.
Data Structure
2
Data Structures: A Pseudocode Approach with C 7
Implementation
Data Structures: A Pseudocode Approach with C 8
Data structure
Data Structures: A Pseudocode Approach with C 9
Algorithms
Create list
Insert node
Delete node
List search
Retrieve node
Empty list
Full list
List count
Traverse list
Destroy list
Data Structures: A Pseudocode Approach with C 10
Create list
Data Structures: A Pseudocode Approach with C 11
Create list
Data Structures: A Pseudocode Approach with C 12
Insert node
Only its logical predecessor is needed.
There are three steps to the insertion:
1. Allocate memory for the new node and move data to the node.
2. Point the new node to its successor.
3. Point the new node’s predecessor to the new node.
Data Structure
3
Data Structures: A Pseudocode Approach with C 13
Insert node
Insert into empty list
Insert at beginning
Insert in middle
Insert at end
Data Structures: A Pseudocode Approach with C 14
Insert into empty list
Data Structures: A Pseudocode Approach with C 15
Insert at beginning
Data Structures: A Pseudocode Approach with C 16
Insert in middle
Data Structures: A Pseudocode Approach with C 17
Insert at end
Data Structures: A Pseudocode Approach with C 18
Data Structure
4
Data Structures: A Pseudocode Approach with C 19
Delete node
Delete first node
General delete case
Data Structures: A Pseudocode Approach with C 20
Delete first node
Data Structures: A Pseudocode Approach with C 21
Delete general case
Data Structures: A Pseudocode Approach with C 22
Data Structures: A Pseudocode Approach with C 23
List search
Data Structures: A Pseudocode Approach with C 24
Data Structure
5
Data Structures: A Pseudocode Approach with C 25 Data Structures: A Pseudocode Approach with C 26
Data Structures: A Pseudocode Approach with C 27
Retrieve node
Data Structures: A Pseudocode Approach with C 28
Empty list
Data Structures: A Pseudocode Approach with C 29
Full list
Data Structures: A Pseudocode Approach with C 30
List count
Data Structure
6
Data Structures: A Pseudocode Approach with C 31
Traversal list
Data Structures: A Pseudocode Approach with C 32
Data Structures: A Pseudocode Approach with C 33 Data Structures: A Pseudocode Approach with C 34
Destroy list