Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Stacks and Queues - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

In the subject of the Data Structures, the key concept and the main points, which are very important in the context of the data structures are listed below:Stacks and Queues, Stack and Heap, First-In-Last-Out Structure, Method Returns, Return Parameters, Basic Architecture, Technique, Recursion, Stack Interface, Push Operations

Typology: Slides

2012/2013

Uploaded on 04/23/2013

saratey
saratey 🇮🇳

4.3

(10)

87 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
7/11/2011 1
Stacks and Queues
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Stacks and Queues - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

7/11/

1

Stacks and Queues

Stack and Heap

• A stack is a first-in-last-out structure 7/11/

2

-^

When a method is called computer stores allrelated data in a place called stack

-^

When the method returns, stack is usedgenerate the return parameters

7/11/

4

A Stack interface

public interface Stack {

public void

push(Object x);

public void

pop();

public Object top();public boolean isEmpty();public void

clear();

7/11/

5

Stacks are LIFO

e d^ c b a

Push

operations:

Implementing Stacks

7/11/

7/11/

8

Implementing stacks using

arrays

• Use an array-based representation. •^

What are some advantages and disadvantages of anarray-based representation?

a^

b

c top

7/11/

10

Queues

•^

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

A Queue interface

public interface Queue {

public void

enqueue(Object

x);

public Object dequeue();public boolean isEmpty();public void

clear();

7/11/

13

Queues are FIFO

front

back

k

r^

q

c^

m

Enqueue y

operation:

7/11/

14

Queues are FIFO

front

back

k

r^

q

c^

m

y

Enqueue

operation:

Implementing Queues

7/11/

Implementing a Queue with an

array

• What are the disadvantages? 7/11/

7/11/

19

A queue from two stacks

j^ i h g f

Enqueue

a b^ c d e

Dequeue

What happenswhen the stackon the rightbecomes empty?

Applications

7/11/