Merge pull request #40 from qualifier1024/patch-9

Update PrintUtil.hpp
pull/43/head
Yudong Jin 2 years ago committed by GitHub
commit 5343ad9f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -210,4 +210,32 @@ class PrintUtil {
printTree(root->left, trunk, false); printTree(root->left, trunk, false);
} }
/**
* @brief Print a stack
*
* @tparam T
* @param stk
*/
template <typename T>
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;
bool flag = true;
while(!tmp.empty()) {
if (flag) {
s << tmp.top();
flag = false;
}
else s << ", " << tmp.top();
tmp.pop();
}
cout << "[" + s.str() + "]" << '\n';
}
}; };

Loading…
Cancel
Save