2. Data Structures
• A way of organizing data so that it can be used
efficiently.
• Choice of data structure determines how
efficiently the program runs.
• Choosing a data structure depends on data
operations and frequency.
• Each data structure requires space for storage,
time for operations
6. Linked List and Nodes
NULLDATANEXTDATANEXTDATANEXTDATA
NEXTDATA
A Node Object
{
Variable to hold data;
Variable to hold next
reference;
}
VALUE REFERENCE
7. Adding to a list
NULLDATANEXTDATANEXTDATANEXTDATA
Last In First Out
NULLDATANEXTDATANEXTDATANEXTDATA
First In Last Out
ADDED
FIRST
ADDED
LAST
ADDED
FIRST
ADDED
LAST
8. Adding the first node
NULLDATA
1. Create an object of type Node which contains value for data and whose next
reference value is null
NULLDATA
FIRST
2. Store the reference to this newly created object in a variable.
9. Adding subsequent nodes
NULLDATA
1. Create an object of type Node which contains value for data and whose next
reference value is null
NEXTDATA
FIRST
2. Append this new node before or after the current node.
Update the NEXT and FIRST references.
NULLDATA