point to note abt anand's code
reason why it does not work
a] when u r doing xor from index 1 to index n( take two cases that n/2
is od or even)
resulting xor will be an xor impression of non repeating number +
either 0 or 1 time the repeating number
now you start xoring again from index zero, so in worst case, xor will
have value equal to a[0], it may or may not be repeating element(all
other numbers will result in zero as they are xored even number of
times)
the expression " if(xor == arr[i])" is luck by chance thing it may be
right, it may not be...
main(){
int arr[]={3,9,3,5,3,6,1,4,3,3};
int len,i,set_bit_no;
int x,y,temp;
x=y=0;
len = sizeof(arr)/sizeof(arr[0]);
int xor = arr[0];
for(i=1;i<len;i++)
{
xor ^= arr[i];
}
printf("xor:%d\n",xor);
for(i=0;i<len;i++)
{
xor ^= arr[i];
if(xor == arr[i])
{
printf("NUM REPEATED:%d\n",arr[i]);
break;
}
}}
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sat, Aug 7, 2010 at 3:25 AM, Manjunath Manohar
<[email protected]>wrote:
> i kinda understood ...u are doing xor on the array twice..but it dint seem
> to work for the array..{2,1,3,2}
> please elaborate ur 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]<algogeeks%[email protected]>
> .
> 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 [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.