lab_quacks
Spiteful Stacks and Questionable Queues
|
Namespace to contain the stack and queue functions for this lab. More...
Functions | |
template<typename T > | |
T | sum (stack< T > &s) |
Sums items in a stack. More... | |
bool | isBalanced (queue< char > input) |
Checks whether the given string (stored in a queue) has balanced brackets. More... | |
template<typename T > | |
void | scramble (queue< T > &q) |
Reverses even sized blocks of items in the queue. More... | |
Namespace to contain the stack and queue functions for this lab.
bool QuackFun::isBalanced | ( | queue< char > | input | ) |
Checks whether the given string (stored in a queue) has balanced brackets.
A string will consist of square bracket characters, [, ], and other characters. This function will return true if and only if the square bracket characters in the given string are balanced. For this to be true, all brackets must be matched up correctly, with no extra, hanging, or unmatched brackets. For example, the string "[hello][]" is balanced, "[[][[]a]]" is balanced, "[]]" is unbalanced, "][" is unbalanced, and "))))[cs225]" is balanced.
For this function, you may only create a single local variable of type stack<char>
! No other stack or queue local objects may be declared. Note that you may still declare and use other local variables of primitive types.
input | The queue representation of a string to check for balanced brackets in |
void QuackFun::scramble | ( | queue< T > & | q | ) |
Reverses even sized blocks of items in the queue.
Blocks start at size one and increase for each subsequent block.
Hint: You'll want to make a local stack variable.
q | A queue of items to be scrambled |
T QuackFun::sum | ( | stack< T > & | s | ) |
Sums items in a stack.
Hint: think recursively!
s | A stack holding values to sum. |