sorry for the above post , there was careless mistake of mine. The code
will be
[code]
int low,mid,high;
low = mid = 0;
high = (int)(sizeof(arr)/sizeof(arr[0]))-1;
/*************************************************************************
According to Dutch national flag problem there are three types of
quantities in an array and we have to combine these elements together
but in a certain order
Let the elements in the array are in the form 0,1,2 then these elements in
an array should appear in order 0 then 1 then 2
( low to middle-1 ) - elements having 0 as a number
(middle to high-1 ) - 1 as a number
( high to arr - size) - 2 as a number
****************************************************************************/
n = high;
while ( mid <= high ) {
if ( arr[mid] == 0 ) {
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if ( arr[mid] == 2 ) {
swap(arr[mid],arr[high]);
high--;
}
else {
mid++;
}
}
[/code]
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.