data structures using object oriented programming
TRANSCRIPT
DATA STRUCTURES
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
Data Structure Examples - Stack
Data Structure Examples - Queue
Data Structure Examples – Linked Lists
NULLDATANEXTDATANEXTDATANEXTDATA
Linked List and Nodes
NULLDATANEXTDATANEXTDATANEXTDATA
NEXTDATA
A Node Object{Variable to hold data;Variable to hold next reference;}
VALUE REFERENCE
Adding to a list
NULLDATANEXTDATANEXTDATANEXTDATA
Last In First Out
NULLDATANEXTDATANEXTDATANEXTDATA
First In Last Out
ADDED FIRST
ADDED LAST
ADDED FIRST
ADDED LAST
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.
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
Inserting node
NEXTDATA NEXTDATA
FIRST
NULLDATA
NULLDATA NEXT
Removing first node
NEXTDATA
FIRST
NEXTDATA NULLDATA
FIRST
Removing specific node
NEXTDATA NULLDATA
CURRENT
NEXTDATANEXTDATA
PREVIOUS
CURRENT CURRENT
PREVIOUS
Match? Match?FOUND!!Match?
What we talked about
• Data structures and why we need them
• How linked lists work
• Adding and removing from a linked list