Skip to content

Commit 21bff32

Browse files
Added solutions
1 parent 1163b83 commit 21bff32

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

amazon/diagonal_sum.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
multimap <int,int> m;
2+
void inorder(Node * root,int hd) {
3+
if(!root) return;
4+
5+
m.insert({hd, root->data});
6+
inorder(root->left, hd+1);
7+
inorder(root->right, hd);
8+
9+
}
10+
11+
void diagonalPrint(Node *root) {
12+
13+
inorder(root,0);
14+
for(auto it=m.begin();it!=m.end();it++)
15+
cout<<it->second<<" ";
16+
m.clear();
17+
18+
}
19+
20+
/*void diagonalPrint(Node *root)
21+
{
22+
// your code here
23+
queue<Node *> q;
24+
q.push(root);
25+
while(!q.empty()){
26+
Node *t=q.front();
27+
while(t){
28+
cout<<t->data<<" ";
29+
if(t->left)
30+
q.push(t->left);
31+
t=t->right;
32+
}
33+
q.pop();
34+
}
35+
}*/

0 commit comments

Comments
 (0)