stack queue

13
Operations on Stack and Queue Dr M M Kazi and Dr Mukti Jadhav Dr. G. Y. Pathrikar College of CS and IT and MIT College Aurangabad [email protected] and [email protected] July 4, 2016 Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 1 / 13

Upload: majharoddin-kazi

Post on 23-Feb-2017

77 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Stack queue

Operations on Stack and Queue

Dr M M Kazi and Dr Mukti Jadhav

Dr. G. Y. Pathrikar College of CS and IT and MIT College Aurangabad

[email protected] and [email protected]

July 4, 2016

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 1 / 13

Page 2: Stack queue

Overview

1 Data Structure

2 Stack

3 Queue

4 Comparison

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 2 / 13

Page 3: Stack queue

Data Structure

You have already come across elementary data types.

Integer

Real

Boolean

And some structured data types (data structures).

String

Array

Record

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 3 / 13

Page 4: Stack queue

Data Structure

Other data structures such as:

Stacks

Queue and

Binary Trees

Have to be constructed by the programmer.

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 4 / 13

Page 5: Stack queue

Stack

Example

The terminology associated with stacks comes from the spring-loadedplate containers you get in canteens.

Figure

In short

They maintain the order LIFO (Last In First Out)

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 5 / 13

Page 6: Stack queue

Stack

Working

New elements are added to the top of the stack. The item at the top ofthe stack is the first to be removed.

Figure

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 6 / 13

Page 7: Stack queue

Queue

Example

Queues are data structures that maintain the order of FIFO (First In FirstOut)

Figure

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 7 / 13

Page 8: Stack queue

Queue

Example

New elements may only be added to the end of a queue; and elementsmay only be retrieved from the front of a queue.

Pointers mark the front and rear of the queue.

Figure

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 8 / 13

Page 9: Stack queue

Comparison: Stack and Queue

Stacks used for

Calculations

Used to store the return address when a subroutine is called

Queue used for

Characters typed at a keyboard are held in a keyboard buffer

Output waiting to be printed is commonly stored in a queue

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 9 / 13

Page 10: Stack queue

Comparison: Stack and Queue

Queues are more difficult to implement than Stacks.

A Stack can be used to reverse a Queue.

Stacks and Queues have preset sizes.

If you try to add an element to a queue or stack that has no freespace you get overflow.

If you try to remove an element from an empty queue or stack youget underflow.

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 10 / 13

Page 11: Stack queue

Citation

The examples and other material are are cited within the presentation:

The course material in this course requires citation [Wikispaces, 2016].

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 11 / 13

Page 12: Stack queue

References

Contributory work (2016)

http://aqaa2computing.wikispaces.com/

Visited on 4 July 2016.

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 12 / 13

Page 13: Stack queue

The End

Dr M M Kazi and Dr Mukti Jadhav (DR GYP) Stack and Queue July 4, 2016 13 / 13