|
|
|
@ -210,34 +210,32 @@ class PrintUtil {
|
|
|
|
|
|
|
|
|
|
printTree(root->left, trunk, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get the Stack String object
|
|
|
|
|
* @brief Print a stack
|
|
|
|
|
*
|
|
|
|
|
* @tparam T
|
|
|
|
|
* @param stack
|
|
|
|
|
* @return string
|
|
|
|
|
* @param stk
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
static string getStackString(stack<T> stack) {
|
|
|
|
|
static void printStack(stack<T> &stk) {
|
|
|
|
|
// Reverse the input stack
|
|
|
|
|
stack<T> tmp;
|
|
|
|
|
while(!stk.empty()) {
|
|
|
|
|
tmp.push(stk.top());
|
|
|
|
|
stk.pop();
|
|
|
|
|
}
|
|
|
|
|
// Generate the string to print
|
|
|
|
|
ostringstream s;
|
|
|
|
|
if(!stack.empty()){
|
|
|
|
|
s << stack.top();
|
|
|
|
|
stack.pop();
|
|
|
|
|
bool flag = true;
|
|
|
|
|
while(!tmp.empty()) {
|
|
|
|
|
if (flag) {
|
|
|
|
|
s << tmp.top();
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
while(!stack.empty()){
|
|
|
|
|
s << ", " << stack.top();
|
|
|
|
|
stack.pop();
|
|
|
|
|
else s << ", " << tmp.top();
|
|
|
|
|
tmp.pop();
|
|
|
|
|
}
|
|
|
|
|
return "top->" + s.str() + "]";
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @brief Print a stack
|
|
|
|
|
*
|
|
|
|
|
* @tparam T
|
|
|
|
|
* @param stack
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
static void printStack(stack<T> &stack) {
|
|
|
|
|
cout << getStackString(stack) << '\n';
|
|
|
|
|
cout << "[" + s.str() + "]" << '\n';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|