Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<queue>
- #include <iostream>
- using namespace std;
- class Node {
- public:
- int data;
- Node * left;
- Node * right;
- Node * parent;
- bool visited;
- Node();
- ~Node();
- };
- Node::Node() {
- Node * n;
- n = new Node;
- n->data = 0;
- n->left = NULL;
- n->right = NULL;
- bool visited = false;
- }
- Node :: ~Node() {
- left = NULL;
- right = NULL;
- parent = NULL;
- }
- class Tree {
- public:
- Tree();
- ~Tree();
- int temp;
- void Aad(Node * root, Node * n);
- int Maximum(Node * root);
- void height(Node * root);
- void distruct(Node * root);
- void Print(Node * root, Node * P);
- void Traverse(Node * root);
- };
- Tree::Tree(){
- Node * root;
- }
- Tree :: ~Tree() {
- }
- void Tree::Aad(Node *root, Node *n) {
- if (n->data > root->data) {
- if (root->right == NULL)
- root->right = n;
- else
- Aad(root->right, n);
- }
- else {
- if (root->left == NULL)
- root->left = n;
- else
- Aad(root->left, n);
- }
- }
- void Tree::height(Node * root) {
- int count = 0;
- int count1 = 0;
- Node *P = root;
- Node *P1 = root->right;
- while (P1->right != NULL) {
- count++;
- P = P1;
- P1 = P1->right;
- }
- P = root;
- P1 = root->left;
- while (P1->left != NULL) {
- count++;
- P = P1;
- P1 = P1->left;
- }
- if (count > count1)
- cout << count << endl;
- else
- cout << count1 << endl;
- }
- int Tree::Maximum(Node *root) {
- if (root->right == NULL)
- return (root->data);
- else
- Maximum(root->right);
- }
- void Tree::distruct(Node * root) {
- if (root->right == NULL)
- return;
- else {
- distruct(root->right);
- delete root->right;
- }
- if (root->left == NULL)
- return;
- else {
- distruct(root->left);
- delete root->left;
- }
- }
- void Tree::Print(Node *root, Node *P) {
- if (P->data > root->data) {
- Print(root->right, P);
- cout << root->data << endl;
- }
- else if (P->data < root->data) {
- Print(root->left, P);
- cout << root->data;
- }
- else
- cout << root->data << endl;
- }
- void Tree::Traverse(Node * root) {
- if (root == NULL)
- cout << "The Tree is empty" << endl;
- queue<Node *> Q;
- Q.push(root);
- while (Q.empty() != true) {
- cout << Q.front();
- if (Q.front()->left != NULL)
- Q.push(Q.front()->left);
- if (Q.front()->right != NULL)
- Q.push(Q.front()->right);
- Q.front()->visited = true;
- Q.pop();
- }
- }
- int main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement