@@ -44,7 +44,7 @@ string strRepeat(string str, int n) {
44
44
return os.str ();
45
45
}
46
46
47
- /* Print an Array */
47
+ /* 打印数组 */
48
48
template <typename T> void printArray (T *arr, int n) {
49
49
cout << " [" ;
50
50
for (int i = 0 ; i < n - 1 ; i++) {
@@ -61,20 +61,20 @@ template <typename T> string getVectorString(vector<T> &list) {
61
61
return " [" + strJoin (" , " , list) + " ]" ;
62
62
}
63
63
64
- /* Print a vector */
64
+ /* 打印列表 */
65
65
template <typename T> void printVector (vector<T> list) {
66
66
cout << getVectorString (list) << ' \n ' ;
67
67
}
68
68
69
- /* Print a vector matrix */
69
+ /* 打印矩阵 */
70
70
template <typename T> void printVectorMatrix (vector<vector<T>> &matrix) {
71
71
cout << " [" << ' \n ' ;
72
72
for (vector<T> &list : matrix)
73
73
cout << " " + getVectorString (list) + " ," << ' \n ' ;
74
74
cout << " ]" << ' \n ' ;
75
75
}
76
76
77
- /* Print a linked list */
77
+ /* 打印链表 */
78
78
void printLinkedList (ListNode *head) {
79
79
vector<int > list;
80
80
while (head != nullptr ) {
@@ -85,10 +85,6 @@ void printLinkedList(ListNode *head) {
85
85
cout << strJoin (" -> " , list) << ' \n ' ;
86
86
}
87
87
88
- /* *
89
- * This tree printer is borrowed from TECHIE DELIGHT
90
- * https://www.techiedelight.com/c-program-print-binary-tree/
91
- */
92
88
struct Trunk {
93
89
Trunk *prev;
94
90
string str;
@@ -98,7 +94,6 @@ struct Trunk {
98
94
}
99
95
};
100
96
101
- /* Helper function to print branches of the binary tree */
102
97
void showTrunks (Trunk *p) {
103
98
if (p == nullptr ) {
104
99
return ;
@@ -108,7 +103,11 @@ void showTrunks(Trunk *p) {
108
103
cout << p->str ;
109
104
}
110
105
111
- /* Print a binary tree */
106
+ /* *
107
+ * 打印二叉树
108
+ * This tree printer is borrowed from TECHIE DELIGHT
109
+ * https://www.techiedelight.com/c-program-print-binary-tree/
110
+ */
112
111
void printTree (TreeNode *root, Trunk *prev, bool isRight) {
113
112
if (root == nullptr ) {
114
113
return ;
@@ -140,12 +139,12 @@ void printTree(TreeNode *root, Trunk *prev, bool isRight) {
140
139
printTree (root->left , &trunk, false );
141
140
}
142
141
143
- /* The interface of the tree printer */
142
+ /* 打印二叉树 */
144
143
void printTree (TreeNode *root) {
145
144
printTree (root, nullptr , false );
146
145
}
147
146
148
- /* Print a stack */
147
+ /* 打印栈 */
149
148
template <typename T> void printStack (stack<T> stk) {
150
149
// Reverse the input stack
151
150
stack<T> tmp;
@@ -167,7 +166,7 @@ template <typename T> void printStack(stack<T> stk) {
167
166
cout << " [" + s.str () + " ]" << ' \n ' ;
168
167
}
169
168
170
- /* Print a queue */
169
+ /* 打印队列 */
171
170
template <typename T> void printQueue (queue<T> queue) {
172
171
// Generate the string to print
173
172
ostringstream s;
@@ -183,7 +182,7 @@ template <typename T> void printQueue(queue<T> queue) {
183
182
cout << " [" + s.str () + " ]" << ' \n ' ;
184
183
}
185
184
186
- /* Print a deque */
185
+ /* 打印双向队列 */
187
186
template <typename T> void printDeque (deque<T> deque) {
188
187
// Generate the string to print
189
188
ostringstream s;
@@ -199,7 +198,7 @@ template <typename T> void printDeque(deque<T> deque) {
199
198
cout << " [" + s.str () + " ]" << ' \n ' ;
200
199
}
201
200
202
- /* Print a HashMap */
201
+ /* 打印哈希表 */
203
202
// 定义模板参数 TKey 和 TValue ,用于指定键值对的类型
204
203
template <typename TKey, typename TValue> void printHashMap (unordered_map<TKey, TValue> map) {
205
204
for (auto kv : map) {
@@ -217,7 +216,7 @@ template <typename T, typename S, typename C> S &Container(priority_queue<T, S,
217
216
return HackedQueue::Container (pq);
218
217
}
219
218
220
- /* Print a Heap (PriorityQueue) */
219
+ /* 打印堆(优先队列) */
221
220
template <typename T, typename S, typename C> void printHeap (priority_queue<T, S, C> &heap) {
222
221
vector<T> vec = Container (heap);
223
222
cout << " 堆的数组表示:" ;
0 commit comments