Professional Documents
Culture Documents
FARRUKH BCS181085 Lab 10
FARRUKH BCS181085 Lab 10
class Node
{
public:
Node * Left;
Node * Right;
int Data;
};
class BST
{
Node *Head;
public:
BST()
{
Head = NULL;
}
if (Head == NULL)
{
Head = temp;
}
else
{
Node *curr = Head;
Node *Parent = NULL;
while (curr != NULL)
{
Parent = curr;
if (curr->Data < temp->Data)
{
curr = curr->Right;
}
else
curr = curr->Left;
}
}
void Inorder(Node *temp)
{
if (temp == NULL)
return;
else
{
Inorder(temp->Left);
cout << temp->Data << "\n";
Inorder(temp->Right);
}
}
bool Search(int val)
{
Node *temp = Head;
if (temp->Data == val)
return true;
else if (val > temp->Data)
{
cout << "Value Dismissed" << endl;
temp = temp->Right;
while (temp != NULL)
{
if (val == temp->Data)
{
cout << "VALUE FOUND " << endl;
return true;
}
else if (val > temp->Data)
temp = temp->Right;
else if (val < temp->Data)
temp = temp->Left;
}
}
else if (val < temp->Data)
{
temp = temp->Left;
while (temp != NULL)
{
if (val == temp->Data)
{
cout << "VALUE FOUND " << endl;
return true;
}
else if (val > temp->Data)
temp = temp->Right;
else if (val < temp->Data)
temp = temp->Left;
}
}
}
};
void main()
{
BST BsT;
int option;
int val;
do
{
cout << "Press 1 to input value " << endl;
cout << "Press 2 to output Display " << endl;
cout << " Press 3 to Search input value " << endl;
switch (option)
{
case 1:
cout << "Enter Value \n";
cin >> val;
BsT.insert(val);
break;
case 2:
BsT.PrintOrder();
break;
case 3:
cout << "nter value \n";
cin >> val;
BsT.Search(val);
}
} while (option != 99 || option != -1);
system("pause");
}