void Matrix::FindPaths(int row, int col, Point& end, Point& start, LinkedList<Point>& one, char** lab, LinkedList<LinkedList<Point>>& paths) { int dr[] = { 0, -1, 0, 1 }; int dc[] = { -1, 0, 1, 0 }; if ((row == end.getX()) && (col == end.getY())) { one.Push_Back(end); paths.Push_Back(one); one.DeleteAll(); one.Push_Back(start); return; } if (lab[row][col] != '.') { return; } Point cur(row, col); one.Push_Back(cur); lab[row][col] = 'p'; for (int i = 0; i < 4; i++) { int x = row + dr[i]; int y = col + dc[i]; Point p(x, y); if (!((x < 0) || (y < 0) || (x >= rows) || (y >= cols))) { FindPaths(x, y, end, start, one, lab, paths); } } lab[row][col] = '.'; }
void FindPaths(TreeNode* root, int expectNumber, vector<int> path, vector<vector<int> >& result, int currSum) { currSum += root->val; path.push_back(root->val); bool isLeaf = (root->left == NULL) && (root->right == NULL); if (currSum == expectNumber && isLeaf) { result.push_back(path); } if (root->left != NULL) { FindPaths(root->left, expectNumber, path, result, currSum); } if (root->right != NULL) { FindPaths(root->right, expectNumber, path, result, currSum); } path.pop_back(); }
vector<vector<int> > FindPath(TreeNode* root,int expectNumber) { if (root == NULL) { return vector<vector<int> >(); } int currSum = 0; vector<int> path; vector<vector<int> > result; FindPaths(root, expectNumber, path, result, currSum); return result; }
/*static*/ status_t BPathFinder::FindPaths(path_base_directory baseDirectory, BStringList& _paths) { return FindPaths(NULL, baseDirectory, NULL, 0, _paths); }
/*static*/ status_t BPathFinder::FindPaths(path_base_directory baseDirectory, const char* subPath, BStringList& _paths) { return FindPaths(NULL, baseDirectory, subPath, 0, _paths); }