1. In infix expression evaluation, we use the notion of ________________ to determine if the expression has too many operators. (Points : 4)
rank
operatorCount
stack precedence
input precedence

2. What is the output from the following sequence of stack operations?
stack<int> stk;
int x = 3, y = 19;
stk.push(6);
stk.push(x);
stk.push(y);
cout << stk.top(); // Output 1 ___________________ (Points : 4)

3. What is the output from the following sequence of stack operations?
stack<int> stk;
int x = 3, y = 19;
stk.push(6);
stk.push(x);
stk.push(y);
stk.pop();
stk.top() *= 4;
stk.push(35);
while (!stk.empty())
{ y = stk.top();
cout << y << " "; // Output 2 ___________________
stk.pop();
}
(Points : 4)

4. A stack is used to reorder an array of integers. Describe the ordering in the integer array arr after executing function f()?
void f(int arr[], int n)
{ stack<int> stk;
int i;
for (i = 0; i < n; i++)
stk.push(arr[i]);
i = 0;
while (!stk.empty())
{ arr[i] = stk.top();
stk.pop();
i++;
}
}
(Points : 4)
creates an ordered array in ascending order
creates an ordered array in descending order
reverses the order of the elements
maintains the same order

5. Assume alist is a list of integer elements and stk is a stack of integers. A pair of loops first copies the elements from the list to the stack and then copies the elements from stack back to the list. Compare the order of the elements  in the original list and the final list.
Loop 1:
while(!alist.empty())
{
stk.push(alist.back());
alist.pop_back();
}
Loop 2:
while(!stk.empty())
{
alist.push_front(stk.top());
stk.pop();
} (Points : 4)
The two copies produce the same ordering in the new list
The two copies reverse the ordering in the new list

6. Indicate whether the ordering specifies a stack (S) or a queue (Q): Last-In-First-Out (LIFO) (Points : 4)
Stack
Queue

7. Indicate whether the ordering specifies a stack (S) or a queue (Q): Last-In-Last-Out (LILO). (Points : 4)
Stack
Queue

8. What is the output from the following sequence of queue operations?
queue<int> q;
int x = 3, y = 5;
q.push(8);
q.push(x);
q.push(y);
cout << q.front(); // Output
(Points : 4)

9. What is the output from the following sequence of queue operations?
queue<int> q;
int x = 3, y = 5;
q.push(8);
q.push(x);
q.push(y);
q.pop();
y = q.front();
q.pop();
q.push(y);
q.push(25);
while (!q.empty())
{ y = q.front();
q.pop();
cout << y << " "; // Output
}
(Points : 4)

10. The function f() in the following reorders the elements in a queue.
template <typename T>
void f(queue<T>& q)
{ vector<T> v;
int n = q.size(), i;
for(i=0;i < n/2; i++)
{ v.push_back(q.front());
q.pop();
}
for (i=0;i < v.size();i++)
q.push(v[i]);
}
Using the initial listing of integer elements in the queue, fill-in the queue after calling f().
Initial values: 1 5 8 10 15 22 55
After calling f(), queue elements: ??? (Points : 4)

## Write a review  