private void QuickSort( int[] a, int left, int right ) { if( a == null ) return; int i = left; int j = right; int pivot = a[( left + right ) / 2]; while( i <= j ) { while( a[i] < pivot ) i++; while( a[j] > pivot ) j--; if( i <= j ) { int tmp = a[i]; a[i++] = a[j]; a[j--] = tmp; } } if( j > left ) { QuickSort( a, left, j ); } if( i < right ) { QuickSort( a, i, right ); } }
An innovative, experienced solutions architect with strong focus on public cloud architecture, solution design and leading technical team. Zhen has 15 years experience designing and implementing a wide spectrum of enterprise level solutions. In the last 4 years, he is committed to evangelising Azure, DevOps and Scrum. His recent focus are enterprise digitisation, cloud governance, reference architecture, IoT, Big Data, Microservices, AWS.
Monday, November 16, 2009
c# Quick Sort Algorithm Implementation
Subscribe to:
Post Comments (Atom)
4 comments:
i think that should be "
if (j > left) Quicksort(a, left, j);
"
After execution it throws Stack Overflow.
It works when you change if condition
replace
if(j>0)
with
if(j>left)
with if (j > left) it works very well.
can you explain to me how this algorithm?
Post a Comment