Presentation is loading. Please wait.

Presentation is loading. Please wait.

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.

Similar presentations


Presentation on theme: "STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations."— Presentation transcript:

1 STACKS & QUEUES

2 Stacks

3 Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations on the data –Error conditions associated with operations

4 The Stack ADT The stack ADT stores arbitary objects Insertions and deletions follow the last-in and first-out scheme Think os a spring-loaded plate dispenser Main stack operations –Push(object): inserts an element –Object pop(): removes and returns the last inserted element

5 Auxiliary stack operations: Object top(): returns the last inserted element without removing it Integer size() returns the number of elements stored Boolean isEmpty(): indicates whether no elements are stored

6 Queues

7 The Queue ADT The queue ADT stores arbitrary objects Insertions and deletions follow the first-in and first –out scheme Insertions are at the rear of the queue and removals are at the front of the queue

8 Main queue operations The queue ADT stores arbitrary objects Enqueue(object): inserts an element at the end of the queue Object dequeue(): removes and returns the element at the front of the queue Object front(): returns the element at the front without removing it Integer size(): returns the element at the front without removing it Integer size(): returns the number of elements stored Boolean is Empty() indicates whether no elements are stored

9 Exceptions Attempting the execution of dequeue or front on an empty queue throws an EmptyQueueException

10 Applications of Queues Direct applications Waiting lists Access to shared resources (e.g printer)


Download ppt "STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations."

Similar presentations


Ads by Google