Lab. Sheet Six: Data Structure Laboratory
Lab. Sheet Six: Data Structure Laboratory
Lab. Sheet Six: Data Structure Laboratory
LABORATORY
if(key_value<leaf->data)
search(key_value, leaf->left);
else
search(key_value, leaf->right);
}
else
cout <<"Node not found..."<<endl;
}
//-------------------------------------inOrder-------------------------
void Tree::inOrder(node* n)
{
if ( n ) {
inOrder(n->left);
cout << n->data << " ";
inOrder(n->right);
}
}
//-------------------------------------PreOrder------------------------
void Tree::PreOrder(node* n)
{
if ( n ) {
cout << n->data << " ";
PreOrder(n->left);
PreOrder(n->right);
}
}
//-------------------------------------PostOrder-----------------------
void Tree::PostOrder(node* n)
{
if ( n ) {
PostOrder(n->left);
PostOrder(n->right);
cout << n->data << " ";
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Tree t;
t.insert(10);
t.insert(2);
t.insert(1);
t.insert(3);
t.insert(7);
t.insert(10);
t.insert(2);
t.insert(5);
t.insert(10);
t.insert(6);
t.insert(4);