diff --git a/CPP/Binary Tree/diagonalViewBinaryTree b/CPP/Binary Tree/diagonalViewBinaryTree new file mode 100644 index 0000000..dfaed01 --- /dev/null +++ b/CPP/Binary Tree/diagonalViewBinaryTree @@ -0,0 +1,45 @@ +#include +using namespace std; +void diagonalview(int tree[], int n) +{ + if(n==0) //if tree is empty + return; + + queue q; + q.push(0); //push root + q.push(-1); //push delimiter + int i=0; //posn of current element left at 2i+1 right at 2i+2 + + while(q.front()!=-1){ //while the queue has elements + + while(q.front()!=-1 )//for each element in queue before the delimiter + { + i=q.front(); + q.pop(); + while(i>n; + int tree[n]; + for(int i=0;i>tree[i]; + + diagonalview(tree, n); + return 0; +}