4.2.3.1 Stacks Flashcards

1
Q

What does pushing do in stacks?

A

Adds a new specified item to the top of the stack

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

What does popping do in stacks?

A

Removes the item from the top of the stack.

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

What does peeking mean in stacks?

A

Returns the value at the top of the stack but doesn’t remove it

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

Write a pseudo-code algorithm for the Push operation to push a value stored in the variable ANumber onto the stack.

A
Function Push(StackArray, TopOfStackPointer, ANumber)
	IF TopOfStackPointer < 20 THEN
		StackArray[TopOfStackPointer] = ANumber
		TopOfStackPointer += 1

End Function

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

Advantages / disadvantages of a stack being implemented using an array

A

Empty entries waste space // Maximum/fixed/static size
Used when the size of the stack /amount of data is known
Memory saved since no pointers

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

Advantages / disadvantages of a stack being implemented using a linked list

A

Space used by pointers // more complex to program

Used when the size of the stack is unknown

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