/** * @param matrix: a matrix of integers * @param k: an integer * @return: the kth smallest number in the matrix */ int kthSmallest(vector<vector<int>> &matrix, int k) { if (matrix.size() < matrix[0].size()) { // Height is smaller. return horizontal_search(matrix, k); } else { // Width is smaller. return vertical_search(matrix, k); } }
struct vector *vertical_rec(struct matrix *img, struct coords block, int win) { int i = vertical_search(img, block); if(i) { struct coords b1, b2; b1 = block, b2 = block; b1.w2 = i; b2.w1 = i; return vector_merge(horizontal_rec(img, b1, 1), vertical_rec(img, b2, 1)); } else { if(win) return horizontal_rec(img, block, 0); else { struct vector *indivisible_block = vector_make(1); indivisible_block->data[0] = block; return indivisible_block; } } }