Lecture7-1 - DataStructures CSCI 132, Spring 2012 Lecture 7...

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 7 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
2 Rules for Calculator use User enters a command: ?, =, +, -, *, or / ? means the next entry is a number. = means print the result (top of stack). All others mean perform the given arithmetic operation.
Background image of page 2
3 Processing commands void do_command(char command ,Stack &numbers) { double p ,q ; switch (command){ case '?': break; case '=': break; cout <<"Enter a real number:" ; cin >>p ; if (numbers.push(p)==overflow) { cout <<"Warning:Stack full,lost number "<<endl; } if (numbers.top(p) == underflow) { cout << "Stack empty." << endl; } else { cout << p <<endl; }
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 More number processing case '+': break; //Add options for further user commands. } //end switch } //end do_command if (numbers.top(p)==underflow){ cout <<"Stack empty "<<endl ; } else { numbers.pop(); if (numbers.top(q)==underflow){ cout <<"Stack has just one entry "<<endl ; numbers.push(p); } else { numbers.pop(); if (numbers.push(q + p)==overflow) { cout <<"Warning:Stack full,lost result "<<endl ; } } }
Background image of page 4
5 Queues A queue is a list in which items are added at one end and deleted from the other end.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 13

Lecture7-1 - DataStructures CSCI 132, Spring 2012 Lecture 7...

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

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