Solución
solution.tsTypeScript
class Stack:
def __init__(self) -> None:
# Inicializa la estructura interna que almacena los elementos
self.stack_list = []
def push(self, value) -> None:
# Agrega el valor al tope
self.stack_list.append(value)
def pop(self):
# Retira y retorna el elemento del tope; retorna None si está vacío
if self.stack_list != []:
return self.stack_list.pop()
return None
def is_empty(self) -> bool:
# Retorna True si no hay elementos
if self.stack_list == []:
return True
return False
def test_stack(operations: list) -> list:
# Crea un Stack, ejecuta cada operación y acumula los resultados
result = []
stack = Stack()
for operation in operations:
if "push" in operation:
stack.push(operation[1])
result.append(None)
elif "pop" in operation:
result.append(stack.pop())
elif "is_empty" in operation:
result.append(stack.is_empty())
return result0respuestas