



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















7/11/
1
2
-^
-^
7/11/
4
public interface Stack {
public void
push(Object x);
public void
pop();
public Object top();public boolean isEmpty();public void
clear();
7/11/
5
e d^ c b a
Push
operations:
7/11/
7/11/
8
What are some advantages and disadvantages of anarray-based representation?
a^
b
c top
7/11/
10
Behavior– add item only from the back (enqueue)– remove items only from the front (dequeue)
-^
Many Applications–
printer queue
-^
network queues
-^
common resource sharing
Queue Operations– enqueue– dequeue– clear– empty– full
7/11/
11
public interface Queue {
public void
enqueue(Object
x);
public Object dequeue();public boolean isEmpty();public void
clear();
7/11/
13
front
back
k
r^
q
c^
m
Enqueue y
operation:
7/11/
14
front
back
k
r^
q
c^
m
y
Enqueue
operation:
7/11/
7/11/
19
j^ i h g f
Enqueue
a b^ c d e
Dequeue
What happenswhen the stackon the rightbecomes empty?
7/11/