class node:
def __init__(self,data,n):
self.data = data
for i in range(n):
a = 'p'+str(i+1)
self.a = None
class custom:
def __init__(self):
self.root = None
self.c = 1
def insert(self,data):
if self.root is None:
self.root = node(data,0)
return
a = self.count()
def _count(self,p):
if p:
a = p
i = 0
while True:
i+=1
try:
v = a.eval('p'+str(i))
self.c += 1
except:
break
return self.c
def count(self):
self.c = 1
return self._count(self.root)
a = node(1,0)
b = node(2,1)
b.p1 = a
c = node(3,2)
c.p1 = a
c.p2 = b
b = custom()
b.root = c
print(c.p1.data)
I wanna create a data structure where a node has one more pointer addreas than the previous node, and the first node has zero, so whenever a node gets created it points to all existing nodes, now i don’t know how to access the nodes using a loop, if a node class has p1,p2,p3 pointers then how do i access them using a loop?
6