| 76 | |
| 77 | |
| 78 | binarytree<int>*takeinputlevelwise() |
| 79 | { |
| 80 | cout<<"enter root data : "; |
| 81 | int rootdata; |
| 82 | cin>>rootdata; |
| 83 | binarytree<int>*root=new binarytree<int>(rootdata); |
| 84 | queue<binarytree<int>*>pendingnodes; |
| 85 | pendingnodes.push(root); |
| 86 | while(pendingnodes.size()!=0) |
| 87 | { |
| 88 | binarytree<int>*front=pendingnodes.front(); |
| 89 | pendingnodes.pop(); |
| 90 | cout<<endl<<"enter left child of "<<front->data<<" : "; |
| 91 | int child; |
| 92 | cin>>child; |
| 93 | if(child!=-1) |
| 94 | { |
| 95 | binarytree<int>*leftchild=new binarytree<int>(child); |
| 96 | front->left=leftchild; |
| 97 | pendingnodes.push(leftchild); |
| 98 | } |
| 99 | cout<<endl<<"enter right chld of "<<front->data<<" : "; |
| 100 | cin>>child; |
| 101 | if(child!=-1) |
| 102 | { |
| 103 | binarytree<int>*rightchild=new binarytree<int>(child); |
| 104 | front->right=rightchild; |
| 105 | pendingnodes.push(rightchild); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return root; |
| 110 | |
| 111 | } |
| 112 | |
| 113 | int countnodes(binarytree<int> *root) |
| 114 | { |