Код: Выделить всё
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)
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-pointers