468,289 Members | 1,766 Online

# How can i write this algorithm to see the output in c#???/

Anybody pls tel me......How to write this sorting algorithm in c# to see the output....

// array of integers to hold values
private int[] a = new int[10] {1,3,67,89,23,45,90,7,34,56};

// number of elements in array
private int x;

// Quick Sort Algorithm
public void sortArray()
{
q_sort( 0, x-1 );
}

public void q_sort( int left, int right )
{
int pivot, l_hold, r_hold;

l_hold = left;
r_hold = right;
pivot = a[left];

while( left < right )
{
while( (a[right] >= pivot) && (left < right) )
{
right--;
}

if( left != right )
{
a[left] = a[right];
left++;
}

while( (a[left] <= pivot) && (left < right) )
{
left++;
}

if( left != right )
{
a[right] = a[left];
right--;
}
}

a[left] = pivot;
pivot = left;
left = l_hold;
right = r_hold;

if( left < pivot )
{
q_sort( left, pivot-1 );
}

if( right > pivot )
{
q_sort( pivot+1, right );
}
}

Pls tel me????
Aug 27 '07 #1
1 1386
Plater
7,872 Expert 4TB
This seems a bit like homework. A lot like homework.
If you want the output after it's been "sorted" then just loop through your array and print out the integers after the call to the sort function(s)..
Aug 27 '07 #2