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

Data Structures Using Object Oriented Programming

  • 1.
  • 2.
    Data Structures • Away 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
  • 3.
  • 4.
  • 5.
    Data Structure Examples– Linked Lists NULLDATANEXTDATANEXTDATANEXTDATA
  • 6.
    Linked List andNodes NULLDATANEXTDATANEXTDATANEXTDATA NEXTDATA A Node Object { Variable to hold data; Variable to hold next reference; } VALUE REFERENCE
  • 7.
    Adding to alist NULLDATANEXTDATANEXTDATANEXTDATA Last In First Out NULLDATANEXTDATANEXTDATANEXTDATA First In Last Out ADDED FIRST ADDED LAST ADDED FIRST ADDED LAST
  • 8.
    Adding the firstnode 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
  • 10.
  • 11.
  • 12.
    Removing specific node NEXTDATANULLDATA CURRENT NEXTDATANEXTDATA PREVIOUS CURRENT CURRENT PREVIOUS Match? Match? FOUND!!Match?
  • 13.
    What we talkedabout • Data structures and why we need them • How linked lists work • Adding and removing from a linked list