| 27 | } |
| 28 | |
| 29 | void printlevelwise(binarytree<int>*root) |
| 30 | { |
| 31 | queue<binarytree<int>*> pendingnode; |
| 32 | pendingnode.push(root); |
| 33 | |
| 34 | while(pendingnode.size()!=0) |
| 35 | { |
| 36 | binarytree<int>*front=pendingnode.front(); |
| 37 | cout<<front->data<<":"; |
| 38 | pendingnode.pop(); |
| 39 | if(front->left) |
| 40 | { |
| 41 | cout<<"L"<<front->left->data<<","; |
| 42 | pendingnode.push(front->left); |
| 43 | } |
| 44 | |
| 45 | if(front->right) |
| 46 | { |
| 47 | cout<<"R"<<front->right->data<<","; |
| 48 | pendingnode.push(front->right); |
| 49 | } |
| 50 | |
| 51 | cout<<endl; |
| 52 | |
| 53 | } |
| 54 | |
| 55 | } |
| 56 | |
| 57 | binarytree<int>* takeinput() |
| 58 | { |