MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / takeinputlevelwise

Function takeinputlevelwise

CPP/binarytreeuse.cpp:78–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78binarytree<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
113int countnodes(binarytree<int> *root)
114{

Callers 1

mainFunction · 0.85

Calls 3

pushMethod · 0.45
sizeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected