 Can someone share the code to convert a tree root to an adjacency list

vector< vector < int > > con(TreeNode* root){

}

I know the logic, just wanted someone who already has the code to share!

You want a `vector<vector<int>>` ? Do we just arbitrarily give the numbers to the node? And do you want the adjacency list as a graph or a tree? As in, do you want the parent of a node included in it’s adjacency list, or just the children?

Tree is also a graph right?

Yeah parent too

Yes, tree is a graph. (An undirected acyclic graph). But you can represent it in an adjacency list just like you would represent a graph, or you can just have a vector for the children of each node (like an N-ary tree).

Well, if you want the adjacency list, this is how id write it:

Code
``````  1 int node = 1;
2 unordered_map<TreeNode*, int> id;
3 queue<TreeNode*> root;
4 q.push(root);
5 while(not q.empty())
6 {
7     TreeNode* cur = q.front(); q.pop();
8     id[cur] = node++;
9     if(cur->left)
10         q.push(cur->left);
11     if(cur->right)
12         q.push(cur->right);
13 }
15 q.push(root);
16 while(not q.empty())
17 {
18     TreeNode* cur = q.front(); q.pop();
19     if(cur->left)
20     {