{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Stack and Queues Notes

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

Info icon This 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
Image of page 1

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

View Full Document Right 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern