Data structure Flashcards
1
Q
is empty
A
def isempty(stk):
if stk==[]:
return true
else:
return false
2
Q
push
A
def push(stk,item):
stk.append(item)
top=len(stk)-1
3
Q
pop
A
def pop(stk):
is isempty(stk):
return “underflow”
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
4
Q
peek
A
def peek(stk):
if isempty(stk):
return “underflow”
else:
top=len(stk)-1
return stk[top]