int i=0;
int j=n-1;
while (i<j) {
while (i<j) && (a[i]<=0) i++;
while (i<j) && (a[j>0) j--;
if (i<j) swap(a[i],a[j]);
else break;
i++; j--;
}

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Wed, Jun 13, 2012 at 9:49 PM, Krishna Kishore
<kknarenkris...@gmail.com>wrote:

> Given a array of integers both positive and negative and you need to shift
> positive numbers to one side
> and negative numbers to other side with the order intact.
> ex. {-1,5,3,-8,4,-6,9} to {-1,-8,-6,5,3,4,9}. This should be done in O(n).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/PebCCcpUXpIJ.
> To post to this group, send email to algogeeks@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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.

Reply via email to