metti il titolo
Cmq.....
codice:// Mat.hpp #ifndef CTREE_HPP_ #define CTREE_HPP_ #include "Define.hpp" /// The tree node typedef struct CTreeNode_t { int x; int y; struct CTreeNode_t* left; struct CTreeNode_t* right; } CTreeNode, *PCTreeNode; /// The tree class class CTree { private: PCTreeNode FRoot; void InternalDestroyCTree(PCTreeNode&); void InternalAdd(int, int, PCTreeNode&); void InternalShowInOrder(PCTreeNode); int InternalSearch(int, PCTreeNode); public: CTree() { FRoot = NULL; }; virtual ~CTree() { InternalDestroyCTree(FRoot); }; void Add(int x, int y); void ShowInOrder(); int Search(int index) { return InternalSearch(index, FRoot); }; }; #endif // CTREE_HPP_ // Ctree.cpp #include "Ctree.hpp" void CTree::InternalAdd(int x, int y , PCTreeNode& ARoot) { if (ARoot == NULL) { ARoot = new CTreeNode; ARoot->x = x; ARoot->y = y; ARoot->left = NULL; ARoot->right = NULL; } else if (n <= ARoot->n) InternalAdd(x, y, ARoot->left); else if (n > ARoot->n) InternalAdd(x, y, ARoot->right); } void CTree::Add(int n) { InternalAdd(n, FRoot); } void CTree::InternalShowInOrder(PCTreeNode P) { if (P->left) InternalShowInOrder(P->left); std::cout << "x = \t" << P->x << "y = \n \t" P->y "\n"; if (P->right) InternalShowInOrder(P->right); } void CTree::ShowInOrder() { std::cout << "Items sorted: "; InternalShowInOrder(FRoot); std::cout << std::endl; } void CTree::InternalDestroyCTree(PCTreeNode& P) { if (P->left) InternalDestroyCTree(P->left); if (P->right) InternalDestroyCTree(P->right); delete P; P = NULL; }


Rispondi quotando