Problem with Quick sort c#

Discussion in 'Visual C# .Net' started by DN Admin, May 5, 2012.

  1. DN Admin

    Staff Member

    Country:
    United States
    Joined:
    Aug 7, 2010
    Location:
    Joliet, IL U.S.A.
    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)<br/>
    {<br/>
    int[] Array = RandomIntArray(7);<br/>
    Sort sorterar = new Sort();<br/>
    sorterar.QuickSort(array);<br/>
    for (int a = 0; a < array.Length; a++)<br/>
    Console.WriteLine(array[a]);<br/>
    Console.ReadLine();<br/>
    }
    The Sort class looks like this:
    public void QuickSort(int[] array, int left, int right)<br/>
    {<br/>
    if( array == null ) <br/>
    return; <br/>
    int i = left; <br/>
    int j = right; <br/>
    int pivot = array[( left + right ) / 2]; <br/>
    while( i <= j ) <br/>
    { <br/>
    while( array < pivot ) <br/>
    i++; <br/>
    while( array[j] > pivot ) <br/>
    j--; <br/>
    if( i <= j ) <br/>
    { <br/>
    int tmp = array; <br/>
    array[i++] = array[j]; <br/>
    array[j--] = tmp; <br/>
    } <br/>
    } <br/>
    if( j > left ) <br/>
    { <br/>
    QuickSort( array, left, j ); <br/>
    } <br/>
    if( i < right ) <br/>
    { <br/>
    QuickSort( array, i, right ); <br/>
    } <br/>
    }<br/>
    }

    I hope someone could knew whats the problem is!<br/>
    Thanks!

    View the full article
     
    #1

Share This Page