I have written the following quicksort without using online help. It seems to be fine, but is there anything to improve?
#include<iostream>
using namespace std;
void quicksort(int*, int, int);
void print(int *p, int n)
{
for(int i=0; i < n; ++i)
cout << p[i] << ' ' ;
cout << endl;
}
int main()
{
int arr[] = {10,10,15,15,23,5,55,8,6,0,32,10,100};
int len = sizeof(arr)/sizeof(int);
cout << "Before sort:\n";
print(arr,len);
quicksort(arr,0,len-1);
cout << "After sort:\n";
print(arr,len);
}
void quicksort(int *arr, int start, int end)
{
if(start >= end)
return;
int pivot = arr[end];
int i=start,j=start;
for(;j < end; ++j)
if(arr[j] < pivot)
{
swap(arr[i],arr[j]);
++i;
}
swap(arr[i],arr[end]);
quicksort(arr,0,i-1);
quicksort(arr,i+1,end);
}