Untitled
unknown
plain_text
2 years ago
1.0 kB
5
Indexable
#include<iostream> using namespace std; class node{ public: int data; node * left, *right; int lth,rth;//if th=1 then it thread node(int x){ data=x; lth=1; rth=1; } class TBT{ public: node*root, *dummy; TBT(){ root=NULL; dummy=new node(-1); dummy->rth=0; dummy->lth=1; dummy->left=dummy; dummy->right=dummy; } void insertnode(); void insert(node *,node *);//bst void preorder(); }; void TBT::insertnode() { node *newnode; int data; cout<<"Enter the node data:"; cin>>data; newnode=new node(data); if(dummy->lth==1)//empty TBT { root=newnode; root->left=dummy; root->right=dummy; dummy->left=root; dummy->lth=1; T->left=newnode; T->lth=0; } else insert(root,newnode); } void TBT::insert(node *T,node *newnode) { if(newnode->data<T->data) { if(T->lth==1) { newnode->lth=T->lth; newnode->left=T->left; newnode->right=T; newnode->rth=1; T->left=newnode; T->lth=0; } else insert(T->left,newnode); } } void TBT::inorder() { }
Editor is loading...