Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

quick sort c++

void quicksort(int a[], int l, int r)
{
	if (l <= r)
	{
		int pivot = a[(l + r)/2];
		int i = l, j = r;
		while (i <= j)
		{
          	//if u wanna sort from high to low
          	//change a[i] > pivot
          	//		 a[j] < pivot
			while (a[i] < pivot)
				i++;
			while (a[j] > pivot)
				j--;
			if (i <= j)
				swap(a[i++], a[j--]);
		}
		if (l < j)
			quicksort(a, l, j);
		if (r > i)
			quicksort(a, i, r);
	}
}
Source by www.stdio.vn #
 
PREVIOUS NEXT
Tagged: #quick #sort
ADD COMMENT
Topic
Name
6+8 =