Lecture10

Lecture10 - Lecture 10: Stacks and Queues CS2134 Stacks...

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

View Full Document Right Arrow Icon
CS2134 Lecture 10: Stacks and Queues
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS2134 Stacks Sequence of data items with access only at one end, the top think of stack of trays in a cafeteria Stack operations (textbook): bool isEmpty( ) const;     const Object& top( ) const;     void makeEmpty( );     void pop( );     void push( const Object & x );     Object topAndPop( );
Background image of page 2
CS2134 Last in first out (LIFO) elements are removed (popped) in the reverse order that they’re put in Useful for reversing a sequence memory management for function calls (stack of activation records) checking that parentheses are balanced evaluating expressions
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS2134 Reversing a sequence stack<char> s; char x; cin >> x; while (x != ‘ ‘) {   s.push(x);      cin>> x; }; // Now all the characters in current  // word are on the stack. // Next, pop them off and output them while !s.isEmpty()      cout << s.topAndPop(); cout << endl;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/09/2009 for the course CS 2134 taught by Professor Hellerstein during the Spring '07 term at NYU Poly.

Page1 / 12

Lecture10 - Lecture 10: Stacks and Queues CS2134 Stacks...

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

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