/************* File WinTreeAnAl.cpp == Windows Last Left Threaded Data Tree Data Analysis functions and or class methods. This file will hold the functions and or class methods that will commit analysis on the Data Tree's data. The functions: This function will find the data tree's median node (by that nodes) key value and set a pointer to that node in the application's TreeData class. void MedianOfDataTree(TreeData* pTD) { *************/ #include "WinTree.h" // WinTree1.h is 'ifndef' so wont be multipled defind // ********************************************************* // ++++++++++ BEGIN function Median O fData Tree +++++++++++ //This function will find the data tree's median node (by that nodes) key value and set a // pointer to that node in the application's TreeData class. void MedianOfDataTree(TreeData* pTD) { int iNumTreeMembers ; // The median of any sample is always found by: 1. arrange sample members in ascending or descending order, int iMedianStringPossition ; // 2. divided by the number of sample members by two, 3. if product is even then that is median's position // is the product, if a remainder then round up to next hole to find median's position. // example: sample size 21, 21/2 == 10 + 1/2, round up to 11. So the 11'th member is the median. TCHAR* szTreeMembers ; TCHAR szMedianMember[16] ; TreeNode* pC = NULL ; pC = pTD->FetchPointerToRoot() ; // pTD pointer to a TreeData Class instantiation. // That TreeData Class has all the tree data needed in this function. wcscpy_s( szMedianMember, 1 , L"\0" ) ; szTreeMembers = pTD->FetchCurrentTreeMembers() ; // List of all tree members in ascending order. iNumTreeMembers = wcslen( szTreeMembers ) ; // Gets number of members. iMedianStringPossition = ( iNumTreeMembers / 2 ) ; // Gets positions of median member, remember int/int == int no remainder. wcsncat_s( szMedianMember, 2, (szTreeMembers + iMedianStringPossition), 1 ) ; // -> strncat(szMedianMember, (0 + position of median), copy one string member) ; // To get pointer to median node must walk through the tree to find it. while( 1 ) { if( wcsncmp( szMedianMember, pC->FetchTreeNodeData(), 1 ) == 0 ) // See Def. of strncmp() function. { pTD->SetPointerMedianNode( pC ) ; break ; } ; if( wcscmp(pC->FetchTreeNodeData(), szMedianMember ) == 1 ) // A > B then 1, go left, else go right { pC = pC->FetchLeftPointer() ; } else { pC = pC->FetchRightPointer() ; } continue ; // Back to top of 'while' to test if this is median. } // End of while(1)... int stop ; stop = 1 ; // Funtions returns void... } // End function Median Of Data Tree... // -------- END function Median Of Data Tree --------------- // *********************************************************