• C++ BST Insert Print,compile via g++ ,the *.cpp asterisk can represent all the files end with cpp


    #include <iostream>
    using namespace std;
    
    class BSTNode
    {
    public:
        BSTNode *root;
        BSTNode *Left;
        BSTNode *Right;
        BSTNode *Parent;
        int Key;
        BSTNode();
        BSTNode* Insert(BSTNode *node,int keyValue);
        void InsertTree(int keyValue);
        void PrintTreeInOrder(BSTNode *node);
        void printTree();
    };
    #include "BSTNode.h"
    
    BSTNode::BSTNode()
    {
        root=NULL;
    }
    
    BSTNode *BSTNode::Insert(BSTNode *node, int keyValue)
    {
        if (node == NULL)
        {
            node = new BSTNode;
            node->Key = keyValue;
            node->Parent = NULL;
            node->Left = NULL;
            node->Right = NULL;
        }
        else if (node->Key < keyValue)
        {
            node->Right = Insert(node->Right, keyValue);
            node->Right->Parent = node;
        }
        else
        {
            node->Left = Insert(node->Left, keyValue);
            node->Left->Parent = node;
        }
        return node;
    }
    
    
    void BSTNode::InsertTree(int keyValue)
    {
        root=Insert(root,keyValue);
    }
    
    void BSTNode::PrintTreeInOrder(BSTNode *node)
    {
        if (node == NULL)
        {
            return;
        }
        PrintTreeInOrder(node->Left);
        cout << node->Key << "\t";
        PrintTreeInOrder(node->Right);
    }
    
    void BSTNode::printTree()
    {
        PrintTreeInOrder(root);
    }
    #include <iostream>
    #include <uuid/uuid.h>
    #include <ctime>
    #include <string.h>
    #include <fstream>
    #include <ostream>
    #include <istream>
    #include <sstream>
    #include <chrono>
    #include <pthread.h>
    #include "BSTNode.h"
    
    using namespace std;
    
    void tree10();
    
    int main()
    {
        tree10();
        return 0;
    }
    
    void tree10()
    {
        int arr[]={10,20,30,15,19,14,13,50,70,100};
        BSTNode bst;
        int len=sizeof(arr)/sizeof(arr[0]);
        cout<<"Len="<<len<<endl;
        for(int i=0;i<len;i++)
        {
            bst.InsertTree(arr[i]);
        }
    
        bst.printTree();
        cout<<"\nFinished in tree10() "<<endl; 
    }
    //Compile 
    
    g++ -g -std=c++2a -I. *.cpp -o h1 -luuid -lpthread

    The *.cpp can stand for multiple files end with .cpp;

    Run ./h1

  • 相关阅读:
    在QT Assistant中添加帮助文档
    虚拟机下不能运行gazebo
    双系统Ubuntu无法访问Windows磁盘分区解决方法
    hexo双线部署及分流
    Apple Tree POJ
    ZOJ 3604 Tunnel Network(凯莱定理)
    C. Neko does Maths(数论 二进制枚举因数)
    Tree Cutting POJ
    Strategic game POJ
    Anniversary party POJ
  • 原文地址:https://www.cnblogs.com/Fred1987/p/15814766.html
Copyright © 2020-2023  润新知