Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.

Similar presentations


Presentation on theme: "Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating."— Presentation transcript:

1 Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating postfix expressions Translating infix notation to postfix notation Activation records Solving problems involving backtracking, e.g finding a path through a maze; solving the n-queens problem

2 Stack Stack Operations push( ) - put a new item on top of a stack.
pop( ) - get the topmost item from the stack and remove it from the stack. peek( ) -get the value of the topmost item from the stack, but do not remove the item from the stack. isEmpty( ) - return true if the stack is empty size ( ) return the number of items on the stack

3 Stack Implementation May be implemented using either an array
a linked list

4 Queue A queue is a linear data structure in which elements are inserted at one end and removed from the other end. Typically, these two ends are called the front and rear, respectively and are maintained via references to the front and rear. Enforces first-in-first-out (FIFO) behavior. The conceptual picture of a queue is that of a waiting line; for example, cars forming a line at a toll booth, or people waiting in line at a bank, or jobs waiting to be serviced by a computer.

5 Queue Uses of Queues Queues are often used to buffer data that is being sent from a fast computer component to another component. e.g. a print spooler. in simulation programs in operating systems Radix sorting

6 Queue Queue Operations
enqueue( )/insert () - add an item at the rear of the queue dequeue()/getFront() get the item from the front of the queue and remove it from the queue. is_empty( ) return true if the queue is empty size ( ) return the number of items in the queue.

7 Queue Implementation Implementation A queue can be implemented using either a circular array a linked list


Download ppt "Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating."

Similar presentations


Ads by Google