Stacks Flashcards

1
Q

What is a stack

A

Abstract data type , last in first out

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

Size()

A

Return top+ 1

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

IsEmpty()

A

FUNCTION is_empty(top)
IF top == -1 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION

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

Peek()

A

FUNCTION peek(stack, top)
IF is_empty(top) == True THEN
PRINT(“Stack is empty - nothing to peek”)
peeked_item = Null
ELSE
peeked_item = stack[top]
ENDIF
RETURN peeked_item
ENDFUNCTION

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

Push(x)

A

FUNCTION push(stack, top, data)
IF is_full(top) == True THEN
PRINT(“Stack is full”)
ELSE
top = top + 1
stack[top] = data
ENDIF
RETURN top
ENDFUNCTION

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

Pop ()

A

FUNCTION pop(stack, top)
IF is_empty(top) == True THEN
PRINT (“Stack is empty - nothing to pop”)
popped_item = Null
ELSE
popped_item = stack[top]
top = top - 1
ENDIF
RETURN (popped_item, top)
ENDFUNCTION

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

isfull()

A

FUNCTION is_full(top)
IF top == MAX_SIZE - 1 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION

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