bool AVL<T>::findHelper(Node* rt, T val){ if(rt == NULL) return false; else if(val < rt->element) return findHelper(rt->left, val); else if(val> rt->element) return findHelper(rt->right, val); else return true; }
double findHelper(int A[], int m, int B[], int n, int k) { if(m > n) return findHelper(B, n, A, m, k); if(m == 0) return B[k-1]; if(k == 1) return min(A[0], B[0]); int posA = min(m, k/2); int posB = k-posA; if(A[posA-1] < B[posB-1]) return findHelper(A+posA, m-posA, B, n, k-posA); else if(A[posA-1] > B[posB-1]) return findHelper(A, m, B+posB, n-posB, k-posB); else return A[posA-1]; }
int findHelper(vector<int>& nums, int k , int start, int end) { int p = partition(nums, start, end); int len = p - start; if (k == len + 1) { return nums[p]; } else if (k < len + 1) { return findHelper(nums, k, start, p - 1); } else { return findHelper(nums, k - len - 1, p + 1, end); } }
void FindCanvas::drawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint) { // Pass in the first y coordinate for y so that we can check to see whether // it is lower than the last draw call (to check if we are continuing to // another line). findHelper(text, byteLength, paint, (const SkScalar*) pos, pos[0].fY, &FindCanvas::addMatchPos); }
void FindEditor::findPrev() { if (!m_option.isValid()) { return; } m_option.backWard = true; findHelper(&m_option); }
void FindEditor::findNext() { if (!m_option.isValid()) { return; } m_option.backWard = false; findHelper(&m_option); }
/*! \reimp */ void ItemViewFindWidget::find(const QString &ttf, bool skipCurrent, bool backward, bool *found, bool *wrapped) { if (!m_itemView || !m_itemView->model()->hasChildren()) return; QModelIndex idx; if (skipCurrent && m_itemView->selectionModel()->hasSelection()) { QModelIndexList il = m_itemView->selectionModel()->selectedIndexes(); qSort(il.begin(), il.end(), indexLessThan); idx = backward ? il.first() : il.last(); } else { idx = m_itemView->currentIndex(); } *found = true; QModelIndex newIdx = idx; if (!ttf.isEmpty()) { if (newIdx.isValid()) { int column = newIdx.column(); if (skipCurrent) if (QTreeView *tv = qobject_cast<QTreeView *>(m_itemView)) if (tv->allColumnsShowFocus()) column = backward ? 0 : m_itemView->model()->columnCount(newIdx.parent()) - 1; newIdx = findHelper(ttf, skipCurrent, backward, newIdx.parent(), newIdx.row(), column); } if (!newIdx.isValid()) { int row = backward ? m_itemView->model()->rowCount() : 0; int column = backward ? 0 : -1; newIdx = findHelper(ttf, true, backward, m_itemView->rootIndex(), row, column); if (!newIdx.isValid()) { *found = false; newIdx = idx; } else { *wrapped = true; } } } if (!isVisible()) show(); m_itemView->setCurrentIndex(newIdx); }
void FindCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { SkPaint::TextEncoding encoding = paint.getTextEncoding(); //For complex text, transform utf16 to glyph if (encoding == SkPaint::kUTF16_TextEncoding) { int mCount = 0; uint16_t *glyphBuf = NULL; glyphBuf = new uint16_t[byteLength]; mCount = paint.textToGlyphs(text, byteLength, glyphBuf, byteLength); SkPaint clonePaint(paint); clonePaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); findHelper(glyphBuf, 2*mCount, clonePaint, &x, y, &FindCanvas::addMatchNormal); delete glyphBuf; return; } findHelper(text, byteLength, paint, &x, y, &FindCanvas::addMatchNormal); }
int BinarySearchTree<Key, Value>::findHelper( BinaryTreeNode<Key, Value>* subRoot, const Key& key, Value& value) { if (subRoot == NULL) { return URANUS_EMPTY_TREE; } else if (subRoot->keyEquals(key) > 0) { return findHelper(subRoot->rightChild(), key, value); } else if (subRoot->keyEquals(key) < 0) { return findHelper(subRoot->leftChild(), key, value); } else { subRoot->value(value); return URANUS_SUCCESS; } }
void FindCanvas::drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { findHelper(text, byteLength, paint, xpos, constY, &FindCanvas::addMatchPosH); }
void FindCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { findHelper(text, byteLength, paint, &x, y, &FindCanvas::addMatchNormal); }
bool AVL<T>::isThere(T val){ return findHelper(root, val); }
double findMedianSortedArrays(int A[], int m, int B[], int n) { if((m+n)&1) return findHelper(A, m, B, n, (m+n)/2+1); else return (findHelper(A, m, B, n, (m+n)/2) + findHelper(A, m, B, n, (m+n)/2+1))/2; }
int findKthSmallest(vector<int>& nums, int k) { return findHelper(nums, k, 0, nums.size() - 1); }