Lecture6-1 - DataStructures CSCI 132, Spring 2012 Lecture 6...

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 6 Applications using Stacks
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 Recall the Stack class typedef int Stack_entry; const int maxstack =10 ; //small value for testing class Stack { public: Stack(); bool empty()const; Error_code pop(); Error_code top(Stack_entry &item)const; Error_code push(const Stack_entry &item); private: int count ; Stack_entry entry [maxstack ]; };
Background image of page 2
3 Implementing push( ) { Error_code outcome =success ; if (count >=maxstack) { outcome =overflow ; } else { entry [count ]=item ; count++; } return outcome ; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Implementing pop( ) Error_code Stack ::pop() { }
Background image of page 4
5 Implementing pop( ) Error_code Stack ::pop() { Error_code outcome =success ; if (count ==0) { outcome =underflow ; } else { count-- ; } return outcome ; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Implementing top( ) { //implement top( ) }
Background image of page 6
7 Implementing top( ) { Error_code outcome =success ; if (count ==0){ outcome =underflow ; } else { item =entry [count - 1]; } return outcome ; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Implementing empty( ) bool Stack ::empty( )const { //implement empty( ) }
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 03/09/2012.

Page1 / 17

Lecture6-1 - DataStructures CSCI 132, Spring 2012 Lecture 6...

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

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