468,289 Members | 1,766 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,289 developers. It's quick & easy.

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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John Flynn | last post: by
2 posts views Thread by Julio C. Hernandez Castro | last post: by
51 posts views Thread by Joerg Schoen | last post: by
22 posts views Thread by Jia Lu | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.