This is the most commonly used in the algorithm of fast sorting, standing up as a fast row, here is the algorithm of two pointers.
Quick Sort
#include <iostream>
#include <cstdio>
using namespace Std;
int partition (int *array, int i, int j)
{
int t = * (Array + 1);
while (I < j)
{
while (I < j && * (Array + j) >= T)
{
j--;
}
if (I < J)
{
* (array + 1) = * (array + j);
i++;
}
while (I < j && * (Array + i) <= t)
{
i++;
}
if (I < J)
{
* (array + j) = * (array + i);
j--;
}
}
* (Array + i) = t;
return i;
}
void QuickSort (int *array, int low, int hight)
{
int mid;
if (Low < high)
{
Mid = Partition (Array, Low, high);
QuickSort (Array, Low, mid-1);
QuickSort (Array, mid + 1, high);
}
}
int main ()
{
int i, n;
int array[255];
printf ("Please enter the number of data \ n");
scanf ("%d", &n);
if (n <= 0 && n >= 255)
{
printf ("The data is unreasonable!" \ n ");
Exit (1);
}
printf ("Enter the data to be sorted in turn: \ n");
for (int i = 1; I <= n; ++i)
{
scanf ("%d", (Array + i));
printf ("\ n" to sort the array is: \ n ");
for (int i = 1; I <= n; ++i)
{
prntf ("%d", * (Array + i));
}
QuickSort (Array, 1, N);
printf ("\ n" the sorted array is: \ n ");
for (int j = 1; j <= N; ++j)
{
printf ("%d", * (Array + j));
}
printf ("\ n");
}
return 0;
}
C Pointer Programming path---eighth notes