int main(int argc,char* argv[]) { Tree T; T = Insert(5,T); T = Insert(3,T); T = Insert(2,T); T = Insert(4,T); T = Insert(6,T); T = Insert(7,T); T = Insert(1,T); preorder(T); printf("\n"); printf("level:%d\n",level(T)); printf("findMaxHeight = %d\n",findMaxHeight(T)); printf("Max = %d\n",FindMax(T)); printf("Minimum = %d\n",FindMin(T)); printf("PreOrder:\n"); preOrder(T); printf("\n"); printf("InOrder:\n"); inOrder(T); printf("\n"); printf("PostOrder:\n"); postOrder(T); printf("\n"); printf("find the lowest ancestor between 1 and 7:\n"); printf("%d\n",findLowestAncestor(T,1,7)); printf("hasSubTree:%d\n",hasSubTree(T,T)); mirrorReverse(T); preOrder(T); printf("\n"); return 0; }
/** * find max height of the bst * Always give unit cost to each node * 1.root 2.left 3.right * **/ int findMaxHeight(bst *root) { int rt = 0; int lt = 0; if(root == 0) { return 1; } else { lt = findMaxHeight(root->left); rt = findMaxHeight(root->right); //The reason to add 1 is to just make sure that you have traversed from top //and you are 1 height below from the top. if(lt < rt) { return rt+1; } return lt+1; } }
int main() { Box arr[] = { {4, 6, 7}, {1, 2, 3}, {4, 5, 6}, {10, 12, 32} }; int n = sizeof(arr)/sizeof(arr[0]); findMaxHeight(arr,n); return 0; }
int main () { int tree_bag[] = {23,12,4,89,34,8,0,67}; int i =0; bst *root = 0; for (; i<7; i++) { make_bst(&root,tree_bag[i]); } printf ("Preorder : \t"); do_preorder(root); printf("\n"); printf ("Inorder : \t"); do_inorder(root); printf("\n"); int ht; ht = findMaxHeight(root); printf("the max height of the tree = %d\n",ht); int no; int k = 3; getkth_max(root,k); printf ("Inorder Before flattening: \t"); do_inorder(root); printf("\n"); flatten_bt(root); //flatten(root); printf ("Inorder After flattening: \t"); do_inorder(root); //do_inorder(t); printf("\n"); }
bool GoalFind::execute(){ getGoalPoles().clearList(); #ifdef _DEBUG Debugger::DEBUG("GoalFind","Start Goal Find!"); #endif const YUVImage* yuvImage = &getImage(); int width = yuvImage->getWidth(); int height = yuvImage->getHeight(); int poleWidth = 0; vector< Object > objectMap; //Iterate trough the Picture from left to Right for (int x = 0; x < width; x++){ //Get the Field line Y for pixel x int y = getFieldLines().getY(x) + mPoleWatchBelowLine; //Get Color Value at Point x,y struct YUVImage::YUVData currentColor = yuvImage->getValue(x,y); //check if color not Green and High Y Value(White) if (currentColor.U > mMaxU_Green || currentColor.V > mMaxV_Green) { if (currentColor.Y >= mMinY_Whitegoal && currentColor.V >= mMinV_Whitegoal && currentColor.U >= mMinU_Whitegoal) { #ifdef _DEBUG if (mDebugDrawings) { DRAW_POINT("Goal", x, y, DebugDrawer::CYAN); } #endif //Used for calculate width of GolePole poleWidth++; //If the White Area end start provide it as goal } else { //Check if line is to small to be a goal Pole if (poleWidth >= mMinPoleWidth) { int topY = y; //Now find out the Height of the Goal Beginning at x,y moving to the Top until its not white int middleX = x - (poleWidth/2); /*while (topY > 0) { struct YUVImage::YUVData col = yuvImage->getValue(middleX,topY); if (col.Y < mMinY_Whitegoal) { break; } topY--; }*/ topY =findMaxHeight(middleX,topY); int botY = y; //Go to the Bottom of the Goal while (botY+1 < height) { struct YUVImage::YUVData col = yuvImage->getValue(middleX,botY); if (col.Y < mMinY_Whitegoal) { break; } botY++; } int poleHeight = botY - topY; if (poleHeight >= mMinPoleHeight) { Object obj(x - poleWidth, topY, poleWidth, poleHeight); obj.type = Object::GOAL_POLE_YELLOW; #ifdef _DEBUG if (mDebugDrawings) { DRAW_BOX("Goal", obj.lastImageTopLeftX, obj.lastImageTopLeftY, obj.lastImageWidth, obj.lastImageHeight, DebugDrawer::BLUE); } #endif objectMap.push_back(obj); } else { #ifdef _DEBUG if (mDebugDrawings) { DRAW_BOX("Goal", x - poleWidth, topY, poleWidth, poleHeight, DebugDrawer::LIGHT_GRAY); } #endif } } poleWidth = 0; } } } // use only the outer objects (left and right) vector< Object >::iterator objIt = objectMap.begin(); if( objIt != objectMap.end()) { Object obj = *objIt; getGoalPoles().addObject(obj); // check if there is a right pole (last in list) and then add it objIt = objectMap.end(); if( --objIt != objectMap.begin()) { obj = *objIt; getGoalPoles().addObject(obj); } } return true; }