C++ Tree node ,when g++ compile multiple cpp files should list them respectively
//TreeNode.h #include <iostream> using namespace std; class TreeNode { public: int val; TreeNode *left; TreeNode *right; TreeNode *NewTreeNode(int keyValue); void treeNode7(); };
//TreeNode.cpp #include "TreeNode.h" TreeNode* TreeNode::NewTreeNode(int keyValue) { //Create a new node TreeNode *node=new TreeNode; //assign a value node->val=keyValue; //Initialize Left and Right pointer node->left=NULL; node->right=NULL; return node; } void TreeNode::treeNode7() { TreeNode *root=NewTreeNode(1); root->left=NewTreeNode(2); root->right=NewTreeNode(3); root->left->left=NewTreeNode(4); root->left->right=NewTreeNode(5); root->right->left=NewTreeNode(6); root->right->right=NewTreeNode(7); cout<<"root->val="<<root->val<<endl; cout<<"root->left->val="<<root->left->val<<endl; cout<<"root->left->left->val="<<root->left->left->val<<endl; cout<<"root->left->right->val="<<root->left->right->val<<endl; cout<<"root->right->left->val="<<root->right->left->val<<endl; cout<<"root->right->right->val"<<root->right->right->val<<endl; }
Compile via
g++ -g -std=c++2a -I. h1.cpp TreeNode.cpp -o h1 -luuid
When compile multiple cpp files ,please add them respectively in the command as above
Run ./h1