I spent some time implementing the quicksort algorithm in C #. After graduation, I compared the speed of my implementation with C # Array.Sort-Method.
I just compare speed with random int arrays.
Here is my implementation:
static void QuickSort(int[] data, int left, int right)
{
int i = left - 1,
j = right;
while (true)
{
int d = data[left];
do i++; while (data[i] < d);
do j--; while (data[j] > d);
if (i < j)
{
int tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
else
{
if (left < j) QuickSort(data, left, j);
if (++j < right) QuickSort(data, j, right);
return;
}
}
}
Performance (when sorting a random int [] with a length of 100000000):
- my algorithm: 14.21 seconds
-.Net Array <int> .Sort: 14.84 seconds
Does anyone know how to implement my algorithm even faster?
Or can someone provide a faster implementation (not necessarily a quick sort!), Which is my run faster?
:
- , , /
- #
, .
EDIT:
, , 8 , ?