Difference in approaches for XOR pair and Subarray with MAX XOR

Here are the links to the codes for MAXXOR function in MAX XOR pair and MAX XOR subarray

pair - https://ide.codingblocks.com/s/441305

subarray - https://ide.codingblocks.com/s/441306

here in the else statement when the bit == 1 ;
why do we need to change the position of current_ans statement?
shouldn’nt the logic remain same ?

Like if bit == 1 then we check if temp -> left != NULL ,
if yes ,
then we increment our current_ans;(for max XOR pair)

but in MAX XOR subarray , it goes in the else statement, that current_ans + = ( 1 << j ) ;
which means that If temp -> left != NULL then just continue to next temp value which doesn’t help us in building the XOR .
Why is this so??

this is the algorithm see:

  1. Create an empty Trie. Every node of Trie is going to
    contain two children, for 0 and 1 value of bit.
  2. Initialize pre_xor = 0 and insert into the Trie.
  3. Initialize result = minus infinite
  4. Traverse the given array and do following for every
    array element arr[i].
    a) pre_xor = pre_xor ^ arr[i]
    pre_xor now contains xor of elements from
    arr[0] to arr[i].
    b) Query the maximum xor value ending with arr[i]
    from Trie.
    c) Update result if the value obtained in step
    4.b is more than current value of result.