Demo entry 6083959

partition

   

Submitted by anonymous on Sep 25, 2016 at 15:26
Language: C. Code size: 318 Bytes.

int partition(int* array, int start, int end)
{
  int pivot = array[end];
  int swapPointer = start;

  for(int i = start; i < end; i++)
  {
    if(array[i] <= pivot)
    {
        swap(array, i, swapPointer);
        swapPointer++;
    }
  }
  swap(array, end, swapPointer);

  return swapPointer;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).