今天又写了delete的部分,时间就这么被一天天地浪费了,我感到十分惋惜呀
1 #pragma once 2 #include "stdio.h" 3 4 struct Node 5 { 6 Node(int aValue) 7 :m_Value(aValue) 8 ,m_pLeft(NULL) 9 ,m_pRight(NULL) 10 ,m_pParent(NULL) 11 { 12 13 } 14 int m_Value; 15 Node* m_pLeft; 16 Node* m_pRight; 17 Node* m_pParent; 18 }; 19 20 class BinarySearchTree 21 { 22 public: 23 BinarySearchTree(void); 24 ~BinarySearchTree(void); 25 void Init(); 26 void Insert(int aValue); 27 void Delete(int aValue); 28 Node* MaxNode(Node* apNode); 29 Node* MinNode(Node* apNode); 30 Node* Search(int aValue); 31 32 void PreOrderPrint(); 33 void AfterOrderPrint(); 34 void MidOrderPrint(); 35 36 void PrintNode( Node* lpNode ) 37 { 38 printf("%d ", lpNode->m_Value); 39 } 40 41 Node* Successor(Node* aNode); 42 43 private: 44 Node* m_pRootNode; 45 };