-
Notifications
You must be signed in to change notification settings - Fork 0
/
binaryTree.hpp
41 lines (34 loc) · 1.32 KB
/
binaryTree.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef BST_BINARYTREE_H
#define BST_BINARYTREE_H
#endif //BST_BINARYTREE_H
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <iostream>
#include <unordered_map>
#include <set>
struct TreeNode{
int val;
TreeNode* left;
TreeNode* right;
};
void preOrfer(TreeNode* root,std::vector<int>& nodes);
void inOrder(TreeNode* root,std::vector<int>& nodes);
void postOrder(TreeNode* root,std::vector<int>& nodes);
void levelOrder(TreeNode* root, std::vector<int>& nodes);
void flatten(TreeNode* root);
std::string getDirections(TreeNode* root, int startValue, int destValue);
//lowest common ancestor
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q);
TreeNode* lowestCommonAncestor2(TreeNode* root, TreeNode* p, TreeNode* q);
std::vector<TreeNode*> delNodes(TreeNode* root, std::vector<int>& to_delete);
int countPairs(TreeNode* root, int distance);
void printVector(std::vector<int> nums);
int getMinimumDifference(TreeNode* root);
std::vector<std::vector<int>> levelOrder(TreeNode* node);
std::vector<std::vector<int>> zigzagLevelOrder(TreeNode* root);
int kthSmallest(TreeNode* root, int k);
int secondMinimum(int n, std::vector<std::vector<int>>& edges, int time, int change);
std::vector<int> shortestDistanceAfterQueries(int n, std::vector<std::vector<int>>& queries);