Question: python explain this is XOR LinkedList. I cannot understand well, can you explain this? Thank you. class Node(object): def __init__(self, val): self.val = val self.both

python explain

this is XOR LinkedList.

I cannot understand well, can you explain this? Thank you.

class Node(object): def __init__(self, val): self.val = val self.both = 0 class XorLinkedList(object): def __init__(self): self.head=self.tail=None self.__nodes=[] #This is to prevent garbage collection def add(self,node): if self.head is None: self.head = self.tail = node else: self.tail.both = id(node)^self.tail.both #why use id() here? node.both=id(self.tail) #why use id() here? self.tail=node self.__nodes.append(node) def get(self, index): prev_id = 0 node = self.head for i in range(index): nex_id = prev_id ^ node.both 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!