{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture7-1

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

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

1 Data Structures   CSCI 132, Spring 2012 Lecture 7 Queues

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

View Full Document
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.
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; }

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

View Full Document
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 ; } } }
5 Queues A queue is a list in which items are added at one end and deleted from the other end.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}