harsha
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class GoogleSort {
public static void main(String args[]) {
int[] in = {-1,2,3,-2,4,-5}; //input array
int temp;//space1
for (int i = 0; i < in.length; ) {
if(in[i]<0) i++;
else{
temp=i;
while(temp < in.length && in[temp]>0 )
temp++;
if(temp >= in.length)
break;
while(i < temp ){
//XOR swap
in[temp] ^= in[temp -1];
in[temp-1] ^= in[temp];
in[temp] ^= in[temp -1];
temp --;
}
i = temp;
}
}
for (int i = 0; i < in.length; i++) {
System.out.println(in[i]);
}
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Guys its so simple. concatenate and XOR, Below is the code:
complexity O(n) time
}
- harsha August 30, 2013