chapter3 (3).doc - Stacks and Queues The Stack Abstract...

This preview shows page 1 - 3 out of 7 pages.

Stacks and Queues The Stack Abstract Data Type The Queue Abstract Data Type A Mazing Problem Evaluation of Expressions Evaluation of Expressions Multiple Stacks and Queues The Stack Abstract Data Type Stack An ordered list Insertions and deletions are made at one end, called top Last-In-First-Out (LIFO) list Illustration Example 3.1:System stack //Fig. 3.2, system stack after function call, p127 -Create a new stack frame for each recursive call. Abstract Data Type Stack template <class KeyType> class Stack { // objects : a finite ordered list with zero or more elements. //for all stack in Stack , item in element, MaxStackSize in positive integer public: Stack ( int MaxStackSize= DefaultSize); //create an empty stack whose maximum size is MaxStackSize 1 Inserting and deleting elements in a stack A B A C B A D C B A E D C B A D C B A top top top top top top
Image of page 1

Subscribe to view the full document.

Boolean IsFull (); //if (number of elements in stack == MaxStackSize ) // return TRUE //else return FALSE void Add ( const KeyType & item ); //if (IsFull( stack )) then StackFull() //else insert item into top of stack Boolean IsEmpty (); //if number of elements in stack is 0, return TRUE
Image of page 2
Image of page 3
  • Spring '13
  • L
  • Pointer, Subroutine, Type theory

{[ 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