// binarytree.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; class node { public: int data; node*roota; node *left; node* right; node(int data) { this->data=data; left=0; right=0; } }; class bt { public: node*roota; node*head; node* anode; bt() {head=0;} void addnodehelper(node*anode, node*current)///////wright the print function {if (current->data==anode->data) {cout<<"already exists"<datadata) { if(current->right) { addnodehelper(anode,current->right); } else { current->right=anode; } } else { if(current->left) { addnodehelper(anode,current->left); } else { current->left=anode; } } } void addnode(int number) { anode=new node(number); if (head==0) { head=anode; return; } addnodehelper(anode,head); return; } void print() { node*roota; Print(roota); return; } void Print(node *root) { if ( root != NULL ) { Print( root->left ); // Print items in left subtree. cout << root->data << " "; // Print the root item. Print( root->right ); // Print items in right subtree. } } }; int _tmain(int argc, _TCHAR* argv[]) { bt binary; int a; int number; do { cout<<"press 1 to add and 2 to print."<>a; if (a==1) { cout<<"add a number "<>number; binary.addnode(number); } if(a==2) { binary.print(); } } while (a==1||a==2); return 0; }