I’m getting Segmentation Fault.
Problem in Implementation
- you are trying to access pos[2] (index ‘2’) while the size of pos is 2.
- in insert function, the code is wrong at loop, it should be i–
- then the correct the condition as:-
if( temp->pos[v] == NULL )
temp->pos[v] = new Trie(); - You need to store the indexes for the data.So dont push data in temp->pos[v]->indexes. Push the index of that data. For keep a count of index, use extra variable in main function and update it for all the queries of type 0.
All don’t forget in maxXor to add the bit to your answer if it is 1.
I hope this will be helpful. I will highly suggest you to understand all these mistakes and correct it on your own, it may take some time but you are in right direction. If you are still not able to correct it, don’t worry, let me know i will share my code with you for reference.
Feel free to ask.
If you are able to solve it now, then please mark this doubt as resolved.
ye samajh nhi aaya kyu krna h…?
@Pramod12
i just mean ki as you traverse down in trie, if temp->pos[v] = 1 then update your answer for that bit. like you are already doing maxXor += 1<<i but you are just doing for if - statement, do it for else statement also.
now I get your point…thank u
soon I’ll do it
@Pramod123
you are not doing count++ for every query of type 1. Also in insert function dont insert indexes for the temp->pos[i] because in this way initial temp, which is our root will not get any indexes, so better push index for temp not any of its child.
Also in binary search you need to compare a and b with v[mid] not mid.
Also never forget print new line after each query of type 1
Also in maxXor function, you should first check whether the taken bit is set or not then only add it to maxV.
Dont initialize maxV with X because you need to find Y not X^Y
In maxXor function() when you are checking using binary search that we can take this index or not then you need pass the vector i.e. temp->pos[1-v]->index because it is the next node to which you are deciding to whether go or not.
I hope this is clear now.
this is corrected code of yours https://ide.codingblocks.com/s/266094
Please mark this doubt as resolved if you have understood it now.
I have to dry Run and need more practice on this toipc.
so many things i’m missing …
and thank you … 
Can you help me understanding trie interview problem