Ejemplo n.º 1
0
void TerminationHelper::runSecondMdrun()
{
    CommandLine secondPart(*mdrunCaller_);
    secondPart.addOption("-cpi", runner_->cptFileName_);
    secondPart.addOption("-nsteps", 2);
    ASSERT_EQ(0, runner_->callMdrun(secondPart));
}
Ejemplo n.º 2
0
void Queue<T>::split(Queue<T> & newQueue){
    size_t middle = getSize() / 2;

    Queue<T> secondPart(*this, middle);

    size_t size = getSize();
    for(size_t i = middle; middle < size; ++middle){
        List<T> :: removeAt(i);
    }

    newQueue = secondPart;
}
Ejemplo n.º 3
0
int inversionUsingSort(vector<int>& v) {
  if (v.size() <= 1) {
    return 0;
  }
  int count = 0;

  // Divide the array into two parts.
  vector<int> firstPart(v.begin(), v.begin() + v.size() / 2);
  vector<int> secondPart(v.begin() + v.size() / 2, v.end());

  count += inversionUsingSort(firstPart);
  count += inversionUsingSort(secondPart);

  // Merge the arrays.
  auto first = firstPart.begin();
  auto second = secondPart.begin();

  size_t idx = 0;
  for (; first != firstPart.end() || second != secondPart.end(); ) {
    if (first == firstPart.end()) {
      v[idx++] = *second;
      second++;
    } else if (second == secondPart.end()) {
      v[idx++] = *first;
      first++;
    } else {
      if (*first <= *second) {
        v[idx++] = *first;
        first++;
      } else {
        // This is the inversion case. We are inserting an element from the
        // second vector into the merged vector. All the remaining elements in
        // the first vector are inversions w.r.t. the element being added from
        // the second. Note that this counts duplicates too.
        count += std::distance(first, firstPart.end());
        v[idx++] = *second;
        second++;
      }
    }
  }
  return count;
}