32 lines
571 B
Python
32 lines
571 B
Python
|
|
class Stack:
|
||
|
|
def __init__(self):
|
||
|
|
self.__stack_list = []
|
||
|
|
|
||
|
|
def push(self, val):
|
||
|
|
self.__stack_list.append(val)
|
||
|
|
|
||
|
|
def pop(self):
|
||
|
|
val = self.__stack_list[-1]
|
||
|
|
del self.__stack_list[-1]
|
||
|
|
return val
|
||
|
|
|
||
|
|
class CountingStack(Stack):
|
||
|
|
def __init__(self):
|
||
|
|
Stack.__init__(self)
|
||
|
|
self.__j = 0
|
||
|
|
|
||
|
|
def get_counter(self):
|
||
|
|
return self.__j
|
||
|
|
|
||
|
|
def pop(self):
|
||
|
|
self.__j += 1
|
||
|
|
return Stack.pop(self)
|
||
|
|
|
||
|
|
|
||
|
|
stk = CountingStack()
|
||
|
|
|
||
|
|
for i in range(100):
|
||
|
|
stk.push(i)
|
||
|
|
stk.pop()
|
||
|
|
|
||
|
|
print(stk.get_counter())
|