コード例 #1
0
 vector<int> searchRange(int A[], int n, int target) {
     vector<int> result(2, -1);
     int l, r;
     l = insertPos(A, n, target - 0.5);
     r = insertPos(A, n, target + 0.5);
     if (l < 0 || r < 0 || l == r) {
         return result;
     }
     else {
         result[0] = l;
         result[1] = r - 1;
         return result;
     }
 }
コード例 #2
0
void
nsScannerString::UngetReadable( const nsAString& aReadable, const nsScannerIterator& aInsertPoint )
    /*
     * Warning: this routine manipulates the shared buffer list in an unexpected way.
     *  The original design did not really allow for insertions, but this call promises
     *  that if called for a point after the end of all extant token strings, that no token string
     *  or the work string will be invalidated.
     *
     *  This routine is protected because it is the responsibility of the derived class to keep those promises.
     */
  {
    Position insertPos(aInsertPoint);

    mBufferList->SplitBuffer(insertPos);
      // splitting to the right keeps the work string and any extant token pointing to and
      //  holding a reference count on the same buffer

    Buffer* new_buffer = AllocBufferFromString(aReadable);
      // make a new buffer with all the data to insert...
      //  BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
      //  of this and decide if we should do the work to fill it

    Buffer* buffer_to_split = insertPos.mBuffer;
    mBufferList->InsertAfter(new_buffer, buffer_to_split);
    mLength += aReadable.Length();

    mEnd.mBuffer = mBufferList->Tail();
    mEnd.mPosition = mEnd.mBuffer->DataEnd();

    mIsDirty = PR_TRUE;
  }
コード例 #3
0
ファイル: main.cpp プロジェクト: Christoph69/PRG1
int main(int argc, char const *argv[]) {
  List tegut;

  initializeList(&tegut);
  std::cout << "Ausgabe first: " << tegut.first << std::endl;
  std::cout << "Ausgabe last: " << tegut.last << std::endl;

  for (int i = 0; i < 3; i++) {
    insert0(&tegut, insertArtikel());

    // std::cout << "Ausgabe first: " << tegut.first << std::endl;
    // std::cout << "Ausgabe last: " << tegut.last << std::endl;
  }

  insertLast(&tegut, insertArtikel());
  insertPos(&tegut, insertArtikel(), 2);
  outputList(&tegut);

  std::cout << "Nach remove0:" << std::endl;
  remove0(&tegut);
  outputList(&tegut);

  std::cout << "Nach removePos:" << std::endl;
  removePos(&tegut, 1);
  outputList(&tegut);

  return 0;
}
コード例 #4
0
 int insertPos (int A[], int n, double target) {
     int res = 0;
     if (n == 0) {
         return 0; 
     }
     if (target < A[0]) {
         return 0;
     }
     if (target > A[n - 1]) {
         return n;
     }
     int midInd = n / 2;
     int midVal = A[midInd];
     if (target == midVal) {
         return INT_MIN;
     }
     if (target < midVal) {
         return insertPos(A, midInd, target);
     }
     else {
         return midInd + 1 + insertPos(&A[midInd + 1], n - midInd - 1, target);
     }
 }
コード例 #5
0
QDocumentCursor CursorHistory::back(const QDocumentCursor &currentCursor) {
	if (currentEntry == history.begin()) {
		updateNavActions();
		return QDocumentCursor();
	}

	// insert currentCursor to be able to go back
	if (currentCursor.isValid() && insertPos(currentCursor, false)) {
		currentEntry--;
	}

	CursorPosition pos(currentCursor);
	if (pos.isValid() && !pos.equals(*currentEntry)) {
		updateNavActions();
		return currentPos();
	}

	currentEntry = prevValidEntry(currentEntry);
	updateNavActions();
	return currentPos();
}