user3812411
user3812411

Reputation: 352

Quicksort using only one argument (vector of ints) and first element as pivot

I need to implement a Quicksort algorithm in C++ which is usually easy but the thing is I can only have the vector as my argument and must choose the first element as pivot. I only have to return the number of comparisons made by my algorithm. This is my function and this cannot be changed since I have no control over the main.cpp file and only have control over the quicksort.cpp and quicksort.h files.

 long long QuickSort(vector<int> & a)

Upvotes: 1

Views: 478

Answers (1)

melpomene
melpomene

Reputation: 85767

Nothing keeps you from making QuickSort call a (recursive) helper function.

For example:

static long long QuickSortWorker(vector<int> &a, size_t start, size_t length) {
    ...
}

long long QuickSort(vector<int> &a) {
    return QuickSortWorker(a, 0, a.size());
}

Upvotes: 3

Related Questions