int searchRow(int i,int j,int no,int a) { int isFound ; if(i==a) { searchRow(i+1,j,no,a); } if(i>8) { return 0; } else if(*(*(ptr+i)+j)==no) { return 1; } else { isFound= searchRow(i+1,j,no,a); } if(isFound==1) { return 1; } else return 0; }
void ContourFinder::combImage(std::vector<MoveBall*>& balls, int numBalls) { float searchGap=(float)img->h; float searchY; while (searchGap>4) { searchY=searchGap/2; while ((int)searchY<img->h) { // if searchRow finds all the balls, return if (searchRow((int)searchY, balls, numBalls)) return; searchY+=searchGap; } searchGap/=2; } }
//-------------------------------------------------------------- void rentRecord::insertRent(int aptNo, int month, float amount) { rentRow searchRow(aptNo); //temp row with same aptNo iter = setPtrsRR.begin(); //search setPtrsRR while( iter != setPtrsRR.end() ) { if(searchRow==**iter) //rentRow found? { //yes, (*iter)->setRent(month, amount); //put rent in row return; } else iter++; } //didn't find it rentRow* ptrRow = new rentRow(aptNo); //make new row ptrRow->setRent(month, amount); //put rent in row setPtrsRR.insert(ptrRow); //put row in vector } // end insertRent()
bool searchMatrix(vector<vector<int>>& matrix, int target) { if(matrix.empty()||matrix[0].empty()) return false; int row=searchRow(matrix,target); if(row==-1) return false; int low=0,high=matrix[0].size()-1,mid; while(low<=high) { mid=low+(high-low)/2; if(matrix[row][mid]==target) return true; else if(matrix[row][mid]>target) high=mid-1; else low=mid+1; } return false; }
bool searchMatrix(vector<vector<int>>& matrix, int target) { int size = matrix.size(); int l = 0; int r = size; int m = 0; while (l < r) { m = l + (r - l) / 2; if (matrix[m][0] <= target) { l = m + 1; } else { r = m; } } for (int i = l - 1; i >= 0; i--) { if (searchRow(matrix[i], target) == true) { cout << matrix[i][0] << endl; return true; } } return false; }
int solveSudoku(int i, int j, int no) { int a=i, b=j; //if(((searchRow(0,j,no,a)==1) || (searchCol(i,0,no,b)==1) || (searchMat(i/3,j/3,a,b,no)==1)) || (no>9)) printf("count= %d ,(%d,%d) = %d\n",count,i,j,no); if(no>9) { printf("count =%d , (%d,%d) = %d\n",count,i,j,no); printf("No Greter than 9 hence backtrack\n"); *(*(ptr+put[count].xCordinate)+put[count].yCordinate) = 0; count -= 1; printf("count =%d, (%d,%d) = %d\n",count,i,j,no); //*(*(ptr+put[count].xCordinate)+put[count].yCordinate) = 0; solveSudoku(put[count].xCordinate,put[count].yCordinate,(put[count].valuePut)+1); //count += 1; // return 1; findEmpty (put[count].xCordinate,put[count].yCordinate); return 1; } /* if(no>9) return 0;*/ //a=i; //b=j; if((searchRow(0,j,no,a)==0) && (searchCol(i,0,no,b)==0) && (searchMat(i/3,j/3,a,b,no)==0)) { *(*(ptr+i)+j)= no; put[count].valuePut = no; count+=1; return 1; } else { solveSudoku(i,j,no+1); return 1; } return 1; }
bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) { if (matrixRowSize == 0) return false; int i = search(matrix, matrixRowSize, target); if (i < 0) return false; return searchRow(matrix[i], matrixColSize, target); }