QWE
QWE
#include<time.h>
using namespace std;
//anouncements
void banner();
class Node;
class BST;
void menu(BST btree);
void loading(int co);
void get();
bool Search(int key);
class Node
{
public:
int data;
Node *left, *right;
Node(int value)
{
data=value;
left=right=NULL;
}
};
class BST
{
public:
Node *root;
BST()
{
root=NULL;
}
Node* Insert(Node *r,int item)
{
int count=0;
// cout<<"r-data="<<r->data<<endl;
if(r==NULL)
{
count++;
r=newnode;
}
else if(item <r->data)
r->left=Insert(r->left,item);
else
r->right=Insert(r->right,item);
return r;
}
void Insert(int item)
{
root= Insert(root,item);
void Preorder(Node*r)//root->left->right
{
if(r==NULL)
return;
cout<<r->data<<"\t";
Preorder(r->left);
Preorder(r->right);
void Inorder(Node*r)//left->root->right
{
if(r==NULL)
return;
Inorder(r->left);
cout<<r->data<<"\t";
Inorder(r->right);
}
void Postorder(Node*r)//left->right->root
{
if(r==NULL)
return;
Postorder(r->left);
Postorder(r->right);
cout<<r->data<<"\t";
else{
//first condition
if(nod->data > ovalue){
update(nod->left,ovalue,nvalue);
//second condition
else if(nod->data <ovalue){
update(nod->right,ovalue,nvalue);
}
//else
else{
nod->data = nvalue;
}
}
}
bool found;
Node* Search(Node *r,int key){
if (r==NULL)
{
cout<<"Not found"<<endl;
return NULL;
found=false;
}
else if ( r->data==key)
{
cout<<"Found"<<endl;
return r;
found=true;
else if(key<r->data)
return Search(r->left,key);
else
return Search(r->right,key);
else if(r->right==NULL)
return r;
else
return FindMax(r->right,value);
}
Node *Delete(Node *ro,int value){
if(ro==NULL)
cout<<"List is empty"<<endl;
if(value<ro->data)
ro->left=Delete(ro->left,value);
else{
if(ro->left==NULL & ro-right==NULL)
ro=NULL;
};
//main function
int main()
{
BST btree;
banner();
//loading();
menu(btree);
//Banner
void banner(){
cout<<"****************************************************************************
*"<<endl;
cout<<"****************************************************************************
*"<<endl;
cout<<" WELCOME"<<endl;
cout<<"****************************************************************************
*"<<endl;
else{
if(nod->left !=NULL){
printT(nod->left);
}
else if(nod->right !=NULL){
printT(nod->right);
}
else{
cout<<nod->data<<",";
}
}
}
cout<<"****************************************************************************
*"<<endl;
cout<<"Choose:\n1- Create a new tree list\n2- Insert to the tree \n3-
Delete \n4- Update \n5- Sort \n6- Search\n7- Print \n8- Quit"<<endl<<">>>";
cin>>choiceM;
switch(choiceM){
//checks
case 1:
cout<<"\n";
cout<<"Creating a new list......"<<endl;
//loading(co);
cout<<"List is successfully created\n";
cout<<"*****************************************************************\n";
cout<<"Enter the root element:"<<endl<<">>>";
cin>>val1;
btree.Insert(val1);
cout<<"*****************************************************************\n";
cout<<"Click M to go to Menu\n>>>";
cin>>clicker;
break;
//checks
case 2:
cout<<"Enter the element to be inserted"<<endl<<">>>";
cin>>val2;
btree.Insert(val2);
cout<<"*****************************************************************\n";
cout<<"Click M to go to Menu\n>>>";
cin>>clicker;
break;
//still
case 3:
cout<<"Enter the element to be deleted\n"<<endl<<">>>";
break;
//checks
case 4:
cout<<"Enter the value to update:\n>>>";
cin>>oval4;
cout<<"Enter the new value:>>>";
cin>>nval4;
btree.update(btree.root,oval4,nval4);
cout<<"*****************************************************************\n";
cout<<"Click M to go to Menu\n>>>";
cin>>clicker;
break;
//checks
case 5:
cout<<"Sorting\n:";
cout<<"******************************************************************"<<endl;
btree.Inorder(btree.root);
break;
case 6:
cout<<"Search:"<<endl;
cout<<"Enter value to strt searching:\n>>>";
cin>>val6;
btree.Search(btree.root,val6);
break;
case 7:
cout<<"printing the tree:"<<endl;
printT(btree.root);
break;
//checks
case 8:
cout<<"quitting:";
loading(co);
run=false;
break;
}
}
}
// loading method
void loading(int co){
int randSec;
int sran;
if(co>0){
srand(time(NULL));
randSec= 30;
sran = rand()%10;
sran+=4*rand()%5;
sran++;
}
else{
co++;
srand(time(NULL));
randSec = 30;
sran = rand()%5;
int ssrand=sran;
cout<<"loading=[";
while(randSec>0){
while(ssrand>0){
cout<<"#";
ssrand--;
}
cout<<"#";
time_t stop= clock() + CLOCKS_PER_SEC;
while(clock()<stop){
}
randSec-=sran++;
}
cout<<"] %100"<<endl;