Data structure Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

is empty

A

def isempty(stk):
if stk==[]:
return true
else:
return false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

push

A

def push(stk,item):
stk.append(item)
top=len(stk)-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

peek

A

def peek(stk):
if isempty(stk):
return “underflow”
else:
top=len(stk)-1
return stk[top]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly