Update stack and queue.

This commit is contained in:
Yudong Jin
2022-11-30 02:27:26 +08:00
parent 53cc651af2
commit 8669e06414
24 changed files with 705 additions and 186 deletions

View File

@ -102,7 +102,7 @@ class PrintUtil {
* @param list
*/
template <typename T>
static void printVector(vector<T> &list) {
static void printVector(vector<T> list) {
cout << getVectorString(list) << '\n';
}
@ -218,7 +218,7 @@ class PrintUtil {
* @param stk
*/
template <typename T>
static void printStack(stack<T> &stk) {
static void printStack(stack<T> stk) {
// Reverse the input stack
stack<T> tmp;
while(!stk.empty()) {
@ -246,7 +246,7 @@ class PrintUtil {
* @param queue
*/
template <typename T>
static void printQueue(queue<T> &queue)
static void printQueue(queue<T> queue)
{
// Generate the string to print
ostringstream s;
@ -261,4 +261,20 @@ class PrintUtil {
}
cout << "[" + s.str() + "]" << '\n';
}
template <typename T>
static void printDeque(deque<T> deque) {
// Generate the string to print
ostringstream s;
bool flag = true;
while(!deque.empty()) {
if (flag) {
s << deque.front();
flag = false;
}
else s << ", " << deque.front();
deque.pop_front();
}
cout << "[" + s.str() + "]" << '\n';
}
};