| 300 | } |
| 301 | |
| 302 | void leveloder(binarytree<int>*root) |
| 303 | { |
| 304 | queue<binarytree<int>*> pendingnodes; |
| 305 | pendingnodes.push(root); |
| 306 | pendingnodes.push(NULL); |
| 307 | |
| 308 | while(pendingnodes.size()!=0) |
| 309 | { |
| 310 | binarytree<int>*front=pendingnodes.front(); |
| 311 | pendingnodes.pop(); |
| 312 | |
| 313 | if(pendingnodes.size()==0) |
| 314 | break; |
| 315 | |
| 316 | if(front==NULL) |
| 317 | { |
| 318 | cout<<endl; |
| 319 | pendingnodes.push(NULL); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | cout<<front->data<<" "; |
| 324 | if(front->left) |
| 325 | pendingnodes.push(front->left); |
| 326 | |
| 327 | if(front->right) |
| 328 | pendingnodes.push(front->right); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | binarytree<int>*removeleafnodes(binarytree<int>*root) |
| 334 | { |