Chapter 3 ADT Notes
Chapter 3 ADT Notes
1 of 11
boolean isEmpty( )
E top( )
E pop( )
Empty stack:
top null
Instance
variables:
-‐-‐
an
array
of
some
CAPACITY
capacity
-‐-‐
an
int
variable
top
–
stores
index
of
last
element
pushed
-‐-‐
an
int
variable
for
size?
7
….
19
20
150
88
30
15
Physical
view
Logical
view
Picture
from
http://courses.cs.vt.edu/csonline/DataStructures/Lessons/StacksImplementationView/index.html
_________________________
_________________________
_________________________
queue2
–
first-‐in
first
out
(like
a
line
of
polite
students
waiting
for
lunch);
add
data
on
one
end,
remove
from
the
other
end
jobs
waiting
on
the
CPU
–
(assuming
no
priority
system)
first
job
in
line
is
done
next
print
jobs
waiting
on
the
printer
to
be
available
orders
waiting
to
be
shipped
queue
ADT:
Basic
operations:
enqueue,
dequeue
Other
operations:
isEmpty,
front,
back
May
be
relevant:
size
Queue
interface
–
• spells
out
the
methods
that
must
be
implemented
for
any
queue;
• as
always….interface
is
implementation
independent
2
Image
from
http://brendan.enrick.com/post/understanding-‐the-‐queue-‐data-‐structure-‐using-‐a-‐simple-‐c-‐
implementation.aspx
Picture
from
http://www.grasshoppernetwork.c
om/Technical/Share/?q=node/168
enqueue-‐ing
new
Node
v:
v
rear.setNext(v);
rear = v;
“q”
dequeue-‐ing
a
node:
Node retrieved = front;
front = front.getNext( );
retrieved.setNext(null);