Abstract Data Type Is A Definition of New Type, Describes Its Data Structure Is An Implementation of ADT. Many ADT
Abstract Data Type Is A Definition of New Type, Describes Its Data Structure Is An Implementation of ADT. Many ADT
1
Abstract Data Types
In Object Oriented Programming data and
the operations that manipulate that data are
grouped together in classes
Abstract Data Types (ADTs) or data
structures or collections store data and allow
various operations on the data to access and
change it
2
The Core Operations
Every Collection ADT should provide a way to:
– add an item
– remove an item
– find, retrieve, or access an item
Many, many more possibilities
– is the collection empty
– make the collection empty
– give me a sub set of the collection
– and on and on and on…
Many different ways to implement these items each
with associated costs and benefits
3
Lists
Items have a position in this Collection
– Random access or not?
Array Lists
– internal storage container is native array
Linked Lists
public class Node
{ private Object data;
private Node next; last
} first
CS 307 Fundamentals of 4
Computer Science
Stacks
Collection with access only to the last
element inserted
Last in first out Data4 Top
insert/push Data3
remove/pop Data2
top Data1
make empty
CS 307 Fundamentals of 5
Computer Science
Operations on stacks
There are four basic operations, stack, push, pop and empty,
that we define in this chapter.
12.6
Figure 12.3 Stack operation
The push operation
The push operation inserts an item at the top of the stack.
The following shows the format.
12.7
Figure 12.4 Push operation
The pop operation
The pop operation deletes the item at the top of the stack.
The following shows the format.
12.8
Figure 12.5 Pop operation
Stack ADT
We define a stack as an ADT as shown below:
12.9
Queues
Collection with access only to the item that
has been present the longest
Last in last out or first in first out
enqueue, dequeue, front
priority queues and deque
Front Back
10
Trees
Root
11
Other Types of Trees
Binary Search Trees
– sorted values
Heaps
– sorted via a different algorithm
AVL and Red-Black Trees
– binary search trees that stay balanced
Splay Trees
B Trees
12