Is this reimplemented quicksort correct? #include&lt;iostream&gt;
using namespace std;

int partition(int arr[],int first,int last,int pivot)
{
    int tmparr[100];
    int left=first,right=last;
    for(int i=first;i&lt;=last;i++)
    {
        if(arr[i]&lt;pivot)
            tmparr[left++]=arr[i];
        else if(arr[i]&gt;pivot)
            tmparr[right--]=arr[i];
    }
    //for the case when pivot is duplicated
    for(int i=left;i&lt;=right;i++)
        tmparr[i]=pivot;
    for(int i=first;i&lt;=last;i++)
        arr[i]=tmparr[i];
    return left;
}
void quicksort(int arr[],int first,int last)
{
    if(first&lt;last)
    {
    int pivotindex = partition(arr,first,last,arr[first]);
    quicksort(arr,first,pivotindex-1);
    quicksort(arr,pivotindex+1,last);
    }

}
int main()
{
    int arr[6]={6,6,9,5,3,7};
    int n=6;
    quicksort(arr,0,n-1);
    for(int i=0;i&lt;n;i++)
    cout&lt;&lt;arr[i];
}



How do I avoid the copying to tmparr? 
How does the current method of copying to tmparr and back affect my time efficiency as opposed to an in-place swap?
Am I missing anything in this code?  It looks much simpler than implementations I could find online.
I know you haven't mentioned anything about this, but I think it should still be addressed.

You should not be passing around C arrays in C++.  The entire array is not passed; it merely decays to a pointer to the array.

Instead, use a storage container such as an std::vector.  These will not decay to pointers, and using such containers is more idiomatic C++.  If you have C++, you can use an std::array instead.

Declare and push back the elements:

std::vector&lt;int&gt; values;

values.push_back(6);
values.push_back(6);
// ...


If you have C++11, initialize an std::array instead:

std::array&lt;int, 6&gt; values = { 6, 6, 9, 5, 3, 7 };


Pass either one to a function:

void func(std::vector&lt;int&gt;&amp; values) {}




void func(std::array&lt;int, 6&gt;&amp; values) {}


You will also no longer need n; storage containers know their sizes.  You can access this value with values.size(), which is of the return type std::size_type.  This is also safer because the returned value will be updated as the container changes size.

If you don't have C++11, display the container with (const) iterators:

std::vector&lt;int&gt;::const_iterator iter;
// OR
std::array&lt;int, 6&gt;::const_iterator iter;

for (iter = values.cbegin(); iter != values.cend(); iter++)
{
    std::cout &lt;&lt; *iter;
}


If you do have C++11, use a range-based for-loop:

for (auto&amp; iter : values)
{
    std::cout &lt;&lt; iter;
}


You can use auto here to give you the correct container type automatically.