/********* WinTree.h Second try to get the tree to work in windows. This file contains; all other *.h files needed, const values needed in the application, TreeNode and TreeData class definitions, (their de-structors are in WinTreeConDes,cpp function prototypes. ******/ #ifndef WINTREE2_H // Keeps file from multiply includs... #define WINTREE2_H #include #include // UNICOD not fully suported in 98. #include // For future auto remove... #include // For future use... #include // For wscanf(...) //********************************************************** //***************** const globals values. ******************* // Number of nodes to hold A...Za...z Data nodes in the tree. const int ciNodeCount = 52; // pause between outputs. const int iWAIT = 40 ; // For future use... // used in ' case WM_SIZE: ' to set vertical scroll bar range and page size const int NUMLINES = 27 ; // used in WM_CREATE to set up child windows for tree member display const int ciRows = 2 ; // This dec is used in WinMain and WinProc so simple to make it a global const TCHAR szChildClass[] = TEXT ("TreeMemberCell_Child"); // Used in geting system time, when you have a set number of timers. // If you were to have ??? timers then use a timeProc... with windows // making up the ID numbers. const int ID_TIMER = 1 ; /********************************************************************* The class methods, and private class data member titles are fairly self explanatory. Set****** sets the data, Fetch**** fetches the data. Each class has a constructor and destructor method. *********************************************************************/ // This class is the actual tree nodes. class TreeNode { public: TreeNode(const TCHAR *) ;// Constructor. Both constructors and de-structors are in WinTreeConDes,cpp ~TreeNode(); // Destructor // Set Node pointers... void SetLeftPointer(TreeNode* TP) { pLeftPoint = TP; return ;}; void SetRightPointer(TreeNode* TP) { pRightPoint = TP; return ;}; void SetLeftThreadPointer(TreeNode* TP) { pLeftThread = TP; return ;}; void SetParentNodePointer(TreeNode* TP) { pParentNode = TP; return ;}; // Fetch Node pointers... TreeNode* FetchLeftPointer() { return pLeftPoint ;}; TreeNode* FetchRightPointer() { return pRightPoint;}; TreeNode* FetchLeftThreadPointer() { return pLeftThread;}; TreeNode* FetchParentNodePointer() { return pParentNode;}; TCHAR* FetchTreeNodeData() { return szData; }; private: TreeNode *pLeftPoint ; // Node to lower left. TreeNode *pRightPoint ; // Node to lower right. TreeNode *pLeftThread ; // Node at point of last left turn down the tree. TreeNode *pParentNode ; // Parent of this Node if any. If NULL then this node Root. TCHAR *szData; // Node Data; }; // End class TreeNode // This class will be used to collect all current tree data. class TreeData { public: TreeData( TreeNode* ) ; // Constructor. Both constructors and de-structors are in WinTreeConDes,cpp ~TreeData() ; // Destructor. // Set Node pointers void SetPointerToRoot(TreeNode* pTN) { pRoot = pTN; return; }; void SetPointerLestSignificantNode(TreeNode* pTN) { pLestSignificantNode = pTN; return; }; void SetPointerMostSignificantNode(TreeNode* pTN) { pMostSignificantNode = pTN; return; }; void SetPointerLastNodeViewed(TreeNode* pTN) { pLastNodeViewed = pTN; return; }; void SetPointerNodeToBeRemoved(TreeNode* pTN) { pNodeToBeRemoved = pTN; return; }; void SetPointerMedianNode(TreeNode* pTN) { pMedianNode = pTN ; return; } ; void SetNodeToCurrentTreeMembers(TreeNode &TN) { strcat(szCurrentTreeMembers, TN.FetchTreeNodeData()); return;}; // Remember strncpy(str1 , str2, n ) ; n must include number of char + 1, the + 1, is for the "\0" NULL. void SetNodeToBeRemoved(TCHAR *szNR) { strncpy(szNodeToRemove, szNR, 2 ); return; }; void SetLastNodeRemoved(TCHAR *szNR) { strncpy(szLastNodeRemoved, szNR, 2 ); return; }; // Set Flag values. Flags used in tree navigation. void SetFlagUpThread(bool fFlag) { fUpThread = fFlag; return; } ; void SetFlagLastNodeReached(bool fFlag) { fLastNodeReached = fFlag; return; } ; void SetFlagLestSignificantNodeReached(bool fFlag) {fLestSignificantNodeReached = fFlag; return; } ; void SetFlagMostSignificantNodeReached(bool fFlag) {fMostSignificantNodeReached = fFlag; return; } ; // Sets the time the last node was removed... void SetTimeStampLNR(SYSTEMTIME st) { st1 = st ; return ; } ; // This class will collect all current data tree key values. void CatTNDtoCurrentTreeMembers(TCHAR* szD) { strcat(szCurrentTreeMembers, szD ); } ; void VoidOutCurrentTreeMembers() { strcpy( szCurrentTreeMembers, "\0" ) ; } ; // iCurrentTreeMemberCount is a tally of the number of current tree nodes. void SetCurrentTreeMemberCount(int i) { iCurrentTreeMemberCount += i ; } ; // Fetch Node pointers TreeNode* FetchPointerToRoot() { return pRoot; }; TreeNode* FetchPointerLestSignificantNode() { return pLestSignificantNode; }; TreeNode* FetchPointerMostSignificantNode() { return pMostSignificantNode; }; TreeNode* FetchPointerLastNodeViewed() { return pLastNodeViewed; }; TreeNode* FetchPointerNodeToBeRemoved() { return pNodeToBeRemoved; }; TreeNode* FetchPointerMedianNode() { return pMedianNode ; } TCHAR* FetchCurrentTreeMembers() { return szCurrentTreeMembers;}; TCHAR* FetchNodeToBeRemoved() { return szNodeToRemove; }; TCHAR* FetchLastNodeRemoved() { return szLastNodeRemoved; }; // Fetch the SYSTEMTIME struc that has the time the last node was removed at... SYSTEMTIME FetchTimeStampLNR() { return st1 ; } ; // Fetch Flag values. Flags used in tree navigation. bool FetchFlagUpThread() { return fUpThread; }; bool FetchFlagLastNodeReached() { return fLastNodeReached; }; bool FetchFlagMostSignificantNodeReached() { return fMostSignificantNodeReached ; } ; bool FetchFlagLestSignificantNodeReached() { return fLestSignificantNodeReached ; } ; // iCurrentTreeMemberCount is a tally of the number of current tree nodes. int FetchCurrentTreeMemberCount( ) { return iCurrentTreeMemberCount; } ; private: TreeNode *pRoot; // Current tree root address. TreeNode *pLestSignificantNode; // Lest Significant Node has data member with lowest value. A...Za...z TreeNode *pMostSignificantNode; // Most Significant Node has data member with highest value A...Za...z TreeNode *pLastNodeViewed; // Last Node viewed in last walk through tree. TreeNode *pNodeToBeRemoved; // The next node to be removed from the tree. TreeNode *pMedianNode ; // The Current tree median node. TCHAR szCurrentTreeMembers[60]; // Current Nodes in Tree. TCHAR szNodeToRemove[4]; // The next Node in the Tree to be removed. TCHAR szLastNodeRemoved[4]; // The last node removed from the Tree with this key value. int iCurrentTreeMemberCount ; // To keep a tally of the number of current tree nodes. bool fUpThread ; // Has a Thread been walked up? bool fLastNodeReached; // Has the last Node in the tree been reached? bool fLestSignificantNodeReached; // Has the Lest Significant Node been readhed? bool fMostSignificantNodeReached; // Has the Lest Significant Node been readhed? SYSTEMTIME st1 ; // Windows system time structure. Holds Year to Millisecond. }; // End class TreeData // ************************************************************ // ++++++++++++++++++ Function prototypes. ++++++++++++++++++++ // Standard Petzold window Window Procedure prototype LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; // This is windows child window procedure prototype. // Will use child windows to form squares in api's gui that will display tree members. // Then user can click on a square to remove the node indicated my the nodes's key value displayed there, if any. LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); // This function will get the current system time when a node is removed. // This system time value can then be displayed on the users' interface. void PrintTimeStamp(HDC, TreeData*, int&, int&, int&); // Creates Tree with 52 Nodes A...Za...z data members. Returns Root pointer. TreeNode* CreateTree() ; // Place a node in the tree according to it key data member's value. bool Position(TreeNode*, TreeNode*); // Test to see if Data Tree Exist? bool DoesTreeExist(TreeData*) ; // Will walk through tree and return with all current node data in ascending order. void FetchAllTreeData(TreeData*); // Will set up a call to RemoveNode function with the information needed // for RemoveNode to complete it operation and will set buffers with data // to be displayed on the current condition of the data tree. void PreRemoveNode(TreeNode*, TreeData*, TCHAR*, TCHAR*, TCHAR*, TCHAR*, TCHAR*, TCHAR* ) ; // Will remove the node pointed to in TreeData as NodeToBeRemoved, // and percolate best of the remaining nodes to // take the place of the node that was removed, if percolation is needed. void RemoveNode(TreeData*); // This function will find the data tree's median node (by that node's) key value and set a // pointer to that node in the application's TreeData class. void MedianOfDataTree(TreeData* ) ; // Basically a cut down version of "FetchAllTreeData" . // This function only has to find the node the user enters the key value of. // If the node is found it's address in loaded into TD as the next node to be removed and TRUE is returned, // it the node is not found in the data tree then FALSE is returned. bool FetchNodeData(TreeData* pTD ) ; void DrawMembersGauge(int, int, int, HWND, TreeData*) ; // These functions do the pointer reassignments that are the percolation process. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++ Percolation function prototypes. ++++++++++++++++ // Perco_one - Perco_five deal with removing the root. void Perco_one( TreeNode* ) ; void Perco_two(TreeNode*, TreeNode* ) ; void Perco_three(TreeNode*, TreeNode* ) ; void Perco_four(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_five(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_six(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_seven(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_eight(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_nine(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; void Perco_ten(TreeNode*, TreeNode*, TreeNode*, TreeNode* ) ; // ------------------ Function prototypes --------------------- // ************************************************************ #endif // End of the ifndef.....