30 lines
516 B
Python
30 lines
516 B
Python
from typing import TypeVar, Generic, List
|
|
|
|
|
|
T = TypeVar('T')
|
|
|
|
|
|
class Stack(Generic[T]):
|
|
def __init__(self):
|
|
self.data: List[T] = []
|
|
|
|
def push(self, item: T):
|
|
self.data.append(item)
|
|
|
|
def pop(self) -> T:
|
|
return self.data.pop(-1)
|
|
|
|
def top(self) -> T:
|
|
return self.data[-1]
|
|
|
|
def size(self) -> int:
|
|
return len(self.data)
|
|
|
|
def is_empty(self) -> bool:
|
|
return len(self.data) == 0
|
|
|
|
stack = Stack[int]()
|
|
stack.push('3')
|
|
stack.push('5')
|
|
print(stack.pop())
|