Skip to content

Commit a96c4d5

Browse files
committed
Add XOR Linked List implementation with doctests
1 parent dd57c90 commit a96c4d5

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

data_structures/linked_list/xor_linked_list.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818

1919
class Node:
20-
def __init__(self, value: int):
20+
def __init__(self, value: int) -> None:
2121
self.value = value
2222
self.both: int = 0 # XOR of prev and next node ids
2323

2424

2525
class XORLinkedList:
26-
def __init__(self):
26+
def __init__(self) -> None:
2727
self.head: Optional[Node] = None
2828
self.tail: Optional[Node] = None
2929
self._nodes = {} # id → node map to simulate pointer references
3030

31+
3132
def _xor(self, a: Optional[Node], b: Optional[Node]) -> int:
3233
return (id(a) if a else 0) ^ (id(b) if b else 0)
3334

0 commit comments

Comments
 (0)