int scSelection::PrevLine( ) { scSelection sortedSelect( *this ); sortedSelect.Sort(); TextMarker& mark = sortedSelect.fMark; TextMarker& point = sortedSelect.fPoint; scTextline* prevTxl; if ( mark.fTxl ) { prevTxl = mark.fTxl; do { prevTxl = prevTxl->GetPrevLogical(); } while ( prevTxl && SameBaseline( mark.fTxl, prevTxl ) ); if ( !prevTxl ) return 0; prevTxl = SearchLeft( prevTxl, mark.fSelMaxX ); if ( !prevTxl ) return 0; mark.fTxl = prevTxl; SelectLocateOnLine( &mark, eCursBackward ); point = mark; } else if ( point.fTxl ) { prevTxl = point.fTxl; do { prevTxl = prevTxl->GetPrevLogical(); } while ( prevTxl && SameBaseline( point.fTxl, prevTxl ) ); if ( !prevTxl ) return 0; prevTxl = SearchLeft( prevTxl, point.fSelMaxX ); if ( !prevTxl ) return 0; point.fTxl = prevTxl; SelectLocateOnLine( &point, eCursBackward ); mark = point; } SetMark( mark ); SetPoint( point ); return mark.fTxl != 0; }
inline void JPSPlus::ExploreFromParentLeft(PathfindingNode * currentNode, DistantJumpPoints * distantJumpPoints) { if (distantJumpPoints->jumpDistance[Up] != 0) SearchUp(currentNode, distantJumpPoints->jumpDistance[Up]); if (distantJumpPoints->jumpDistance[UpLeft] != 0) SearchUpLeft(currentNode, distantJumpPoints->jumpDistance[UpLeft]); if (distantJumpPoints->jumpDistance[Left] != 0) SearchLeft(currentNode, distantJumpPoints->jumpDistance[Left]); if (distantJumpPoints->jumpDistance[DownLeft] != 0) SearchDownLeft(currentNode, distantJumpPoints->jumpDistance[DownLeft]); if (distantJumpPoints->jumpDistance[Down] != 0) SearchDown(currentNode, distantJumpPoints->jumpDistance[Down]); }
inline void JPSPlus::ExploreFromParentAllDirections(PathfindingNode * currentNode, DistantJumpPoints * distantJumpPoints) { SearchDown(currentNode, distantJumpPoints->jumpDistance[Down]); SearchDownRight(currentNode, distantJumpPoints->jumpDistance[DownRight]); SearchRight(currentNode, distantJumpPoints->jumpDistance[Right]); SearchUpRight(currentNode, distantJumpPoints->jumpDistance[UpRight]); SearchUp(currentNode, distantJumpPoints->jumpDistance[Up]); SearchUpLeft(currentNode, distantJumpPoints->jumpDistance[UpLeft]); SearchLeft(currentNode, distantJumpPoints->jumpDistance[Left]); SearchDownLeft(currentNode, distantJumpPoints->jumpDistance[DownLeft]); }
vector<int> searchRange(vector<int>& nums, int target) { vector<int> res(2,-1); if(nums.empty()) return res; int left=SearchLeft(nums,target),right=SearchRight(nums,target); if(left<=right) { res[0]=left; res[1]=right; } return res; }
int main() { int i; BiTreeNode *q[MaxSize+1]; BiTreeNode *root; int left,right,temp; int Num[MaxSize]={0}; char strA[MaxSize]="befcgdh";//pre_order char strB[MaxSize]="febgchd";//in_order char point;int n; n=strlen(strA); Initiate(&root); for(i=0;i<n;i++) { point=strA[i]; temp=Search(strB,point); left=SearchLeft(Num,temp); right=SearchRight(Num,temp); if(left==-1&&right==-1) { q[temp]=InsertLeftNode(root,point); Num[temp]=1; } else if(left!=-1&&q[left]->rightChild==NULL) { q[temp]=InsertRightNode(q[left],point); Num[temp]=1; } else if(right!=-1&&q[right]->leftChild==NULL) { q[temp]=InsertLeftNode(q[right],point); Num[temp]=1; } } PrintBiTree(root,0); printf("****************************************\n\n"); printf("PreOrder: \t"); PreOrder(root->leftChild,Visit); printf("\nInOrder:\t"); InOrder(root->leftChild,Visit); printf("\nPostOrder: \t"); PostOrder(root->leftChild,Visit); printf("\n*****************************************************************************\n\t\t\t\bCopyright @ 2009 Gary All Right Reserved\n"); return 0; }
static scTextline* SearchRight( scTextline* leftLineSegment, MicroPoint selmax ) { scTextline* nextTxl = 0; scTextline* rightLineSegment = 0; for( nextTxl = leftLineSegment; nextTxl && SameBaseline( nextTxl, leftLineSegment ); nextTxl = nextTxl->GetNext() ) { rightLineSegment = nextTxl; } return SearchLeft( rightLineSegment, selmax ); }