Stack and Queues Notes

Stack and Queues Notes - Stacks and Queues CpE 360 –...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Stacks and Queues CpE 360 – Computational Algorithms and Data Structures Instructor: Ashish Patel Stacks and queues are, perhaps the most frequently used data structures. Both are restricted version of the linear or ordered list data structure. In fact, stacks and queues are so widely used that C++ STL provides the class stack and queue, which are array implementations of theses data structures. Stacks: Definition: A stack is a linear list in which insertions (also called additions and pushes ) and removals (also called deletions and pops ) take place at the same end. This end is called the top ; the other end of the list is called bottom . A stack is a container of objects/elements that are inserted and removed according to the Last in First-out (LIFO) principle. Elements can be inserted into a stack at amy time, but only the most recently inserted element can be removed at any time. The name "stack" derived from the metaphor of a stack of plates in a spring loaded, cafeteria plate dispenser. In this case, the fundamental operations involve the "pushing" and "poping" of plates on the stack. When we need a new plate from the dispenser, we pop the top plate off the stack, and when we add a plate, we push it down to the stack to become the new top plate. The following figure-1 shows the operation of spring loaded plate dispenser. These push and pop operations are based on LIFO principle. Figure-1 - Spring Loaded Plate Dispenser
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Stacks are fundamental data structure. They are used in many applications, including the following. Internet web browsers store the addresses of recently visited sites on the stack. Each time a user visits a new site, that site's address is "pushed" onto the stack addresses. The browser then allows the user to "pop" back to previously visited sites using the "back" button. Text editors usually provide an "undo" mechanism that cancels recent editing operations and reverts to former states of a document. This undo operation can be accomplished by keeping text changes in a stack. Operations: A stack is an abstract data type (ADT) that supports the following core operations: Push(x): Insert element x at the top of the stack. Input --> element; output --> none. Pop(): Remove from the stack and return the top element on the stack; an error occur if the stack is empty. Input --> none; output --> element. Size(): Return the number of elements in the stack. Input --> none; output --> Integer. Empty(): True if the stack is empty, false otherwise. Input --> none; output --> Boolean
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2010 for the course CPE CPE 360 taught by Professor Jenniferchen during the Spring '10 term at Stevens.

Page1 / 10

Stack and Queues Notes - Stacks and Queues CpE 360 –...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online