Hi, i have tried to do a quick sort in c#. I have no errors in the code, but in my program i get errors.
My code looks like this in the program: And it complains at "array" which doesn't exist in the currrent context.
static void Main(string[] args)
{
int[] Array = RandomIntArray(7);
Sort sorterar = new Sort();
sorterar.QuickSort(array);
for (int a = 0; a < array.Length; a++)
Console.WriteLine(array[a]);
Console.ReadLine();
}
The Sort class looks like this:
public void QuickSort(int[] array, int left, int right)
{
if( array == null )
return;
int i = left;
int j = right;
int pivot = array[( left + right ) / 2];
while( i <= j )
{
while( array[i] < pivot )
i++;
while( array[j] > pivot )
j--;
if( i <= j )
{
int tmp = array[i];
array[i++] = array[j];
array[j--] = tmp;
}
}
if( j > left )
{
QuickSort( array, left, j );
}
if( i < right )
{
QuickSort( array, i, right );
}
}
}
I hope someone could knew whats the problem is!
Thanks!
View the full article




Sign In
Create Account
Back to top







