You can refer to this sample code i had tried to sort in a single pass: #include<iostream.h> #include<conio.h>
using namespace std; int main() { int a = 0, b=1, c=9; int s[10]= { 2,1,0,1,1,0,2,1,0,1}; while(a<b && b<c) { while(s[a]==0) a++; while(s[b]==1 || b<=a) b++; while(s[c]==2 && c>b) c--; if(!(a>=b) && !(b>=c)) { if(s[b]==0) { s[b]=s[a]; s[a]=0; } if(s[b]==2) { s[b]=s[c]; s[c]=2; } } for(int i = 0; i<10; i++) { cout<<s[i]; } cout<<"\n"; } getch(); } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.