Format C++ codes in Clang-Format Style: Microsoft

This commit is contained in:
krahets
2023-04-14 03:44:02 +08:00
parent f8513455b5
commit 9c9c8b7574
46 changed files with 732 additions and 888 deletions

View File

@@ -10,8 +10,9 @@
vector<int> vec;
/* 前序遍历 */
void preOrder(TreeNode* root) {
if (root == nullptr) return;
void preOrder(TreeNode *root) {
if (root == nullptr)
return;
// 访问优先级:根节点 -> 左子树 -> 右子树
vec.push_back(root->val);
preOrder(root->left);
@@ -19,8 +20,9 @@ void preOrder(TreeNode* root) {
}
/* 中序遍历 */
void inOrder(TreeNode* root) {
if (root == nullptr) return;
void inOrder(TreeNode *root) {
if (root == nullptr)
return;
// 访问优先级:左子树 -> 根节点 -> 右子树
inOrder(root->left);
vec.push_back(root->val);
@@ -28,40 +30,40 @@ void inOrder(TreeNode* root) {
}
/* 后序遍历 */
void postOrder(TreeNode* root) {
if (root == nullptr) return;
void postOrder(TreeNode *root) {
if (root == nullptr)
return;
// 访问优先级:左子树 -> 右子树 -> 根节点
postOrder(root->left);
postOrder(root->right);
vec.push_back(root->val);
}
/* Driver Code */
int main() {
/* 初始化二叉树 */
// 这里借助了一个从数组直接生成二叉树的函数
TreeNode* root = vecToTree(vector<int> { 1, 2, 3, 4, 5, 6, 7 });
TreeNode *root = vecToTree(vector<int>{1, 2, 3, 4, 5, 6, 7});
cout << endl << "初始化二叉树\n" << endl;
PrintUtil::printTree(root);
printTree(root);
/* 前序遍历 */
vec.clear();
preOrder(root);
cout << endl << "前序遍历的节点打印序列 = ";
PrintUtil::printVector(vec);
printVector(vec);
/* 中序遍历 */
vec.clear();
inOrder(root);
cout << endl << "中序遍历的节点打印序列 = ";
PrintUtil::printVector(vec);
printVector(vec);
/* 后序遍历 */
vec.clear();
postOrder(root);
cout << endl << "后序遍历的节点打印序列 = ";
PrintUtil::printVector(vec);
printVector(vec);
return 0;
}