mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-19 20:55:57 +08:00
Add C++ code for the chapter binary tree.
This commit is contained in:
@ -238,4 +238,27 @@ class PrintUtil {
|
||||
}
|
||||
cout << "[" + s.str() + "]" << '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @tparam T
|
||||
* @param queue
|
||||
*/
|
||||
template <typename T>
|
||||
static void printQueue(queue<T> &queue)
|
||||
{
|
||||
// Generate the string to print
|
||||
ostringstream s;
|
||||
bool flag = true;
|
||||
while(!queue.empty()) {
|
||||
if (flag) {
|
||||
s << queue.front();
|
||||
flag = false;
|
||||
}
|
||||
else s << ", " << queue.front();
|
||||
queue.pop();
|
||||
}
|
||||
cout << "[" + s.str() + "]" << '\n';
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user