Monash University > CSSE > CSE1303 > Part A > Tutorials > Tutorial A2
This tute covers material from lectures A03 to A04.
There may not be time in the tutorial to cover all of these questions. Attempt at least the ones marked with an asterisk before the tutorial; these are the ones that will be focussed on during the class. If you have specific questions about unmarked questions, you can ask the tutor about them during the tutorial. If you want further revision questions, suggestions of questions from the textbooks are provided at the end of the tutorial sheet.
Note: The purpose of tutorials is not simply to give you the answers to these questions! (Solutions will be released in about a week online, so if all you want is the answers, there are easier ways.)
Assume MAXSTACK has been defined as 5, and Stack and the functions operating on Stack have been defined as in lectures. Show the contents of theStack after each pop and push in the following code. For theStack.entry show only the items in the array which correspond to items on the stack.
float x; float y; Stack theStack; initializeStack(&theStack); push(&theStack, 1.2); push(&theStack, 1.0); x = pop(&theStack); y = pop(&theStack); push(&theStack, y - x); push(&theStack, 4.9); push(&theStack, 5.1); x = pop(&theStack); y = pop(&theStack); push(&theStack, y + x); x = pop(&theStack); y = pop(&theStack); y *= x;
What is the value of y at the end of the computation?
Assume MAXQUEUE has been defined as 5, and Queue and the functions operating on Queue have been defined as in lectures. Show the contents of theQueue after each append and serve. For theQueue.entry show only those items in the array that correspond to items in the queue.
float x;
int n = 10;
Queue theQueue;
initializeQueue(&theQueue);
while (n != 0 && !queueFull(&theQueue))
{
append(&theQueue, n);
n /= 2;
}
while (!queueEmpty(&theQueue))
{
x = serve(&theQueue);
append(&theQueue, --x);
if (x > 4)
{
break;
}
}
What is the value of x at the end of the computation?
| Infix | Reverse Polish |
| a + b*c | a b c * + |
| a + (b*c) | a b c * + |
| (a + b)*c | a b + c * |
| a*b + c | a b * c + |
| a*(b + c) | a b c + * |
| (a + b)*(c - d) | a b + c d - * |
| (a + b)*(c - d)/(e + f) | a b + c d - * e f + / |
Write the following 'infix' expressions in Reverse Polish Notation
(a) (8 + 7) * (3 + 2) + 4 / 3
(b) (3 - 4 + 2) * 7 + 1
Write the following Reverse Polish expressions in infix notation
(c) 5 3 + 4 7 - * 2 /
(d) 7 2 3 + * 5 -
Deitel & Deitel (2nd Edition)
Self Review Exercises 12.1 a, e, j, 12.3
Exercises 12.10, 12.11, 12.12
Last modified: Tuesday 02 December 2003 22:29:33