Ngăn xếp S được cài đặt bằng mảng T có N phân tử, phần tử đầu tiên có chỉ số 0. Hãy viết các hàm cơ bản trên ngăn xếp S.
Giải thích
def push(S, x):
try:
if not S.stackOverflow():
S.topldx += 1
S.T[S.topldx] = x
except ValueError as e:
print(e)
def pop(S):
if S.isEmpty():
raise IndexError(“Ngăn xếp rỗng!")
item = S.T[S.topldx]
S.T[S.topldx] = None
S.topldx -= 1
return item
def isEmptyStack(S):
return S.topldx == -1
def isFull(S):
return S.topldx == self.size - 1