Stacks Flashcards

(14 cards)

1
Q

What are stacks comprised of?

A
  • A sequence of items
  • A stack pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

On what kind of basis is date retrieved from a stack?

A

Last-In-First-Out

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

What are the key operations of a stack?

A
  • Push
  • Pop
  • Peek
  • Test for empty stack
  • Test for full stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a stack overflow?

A

An attempt is made to push more data onto the stack that it can store

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

What is a stack underflow?

A

Occurs when a pop is attempted on an empty stack.

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

What are the uses of stacks?

A
  • Reversing sequences of items
  • Maintaining “undo” lists in applications
  • Maintaining a web-browser history
  • Storing processor state (register values) when handling an interrupt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Test if a stack is empty?

A

Check if the stack pointer is equal to -1

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

Test if a stack is full?

A

Compare the stack pointer to the maximum size of the array (-1)

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

Push an item onto a stack?

A
  1. Check if the stack is full if not…
  2. Increment the stack pointer by 1
  3. Assign the pushed item to the element within stack indexed by the stack pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Peeking a stack?

A
  1. Check if the stack is empty, if not…
  2. Save the item in element indexed by the stack pointer to a variable
  3. Return variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Popping a stack?

A
  1. Check if the stack is empty, if not…
  2. Decrement the stack pointer
  3. Return the item at the stack pointer + 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the call stack

A

-The call stack is an area of memory used to store data used by running processes and subroutines.

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

How does call stack work?

A
  • With each new function/subroutine call a stack frame is pushed onto the call stack.
  • When a process completes, its stack frame is popped off the call stack and the previous process continues.
  • Each stack frame contains local variables, parameter values and return addresses for each “open” subroutine within a process.
  • Only the stack frame at the top of the stack is actively processed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What information does a stack frame contain

A
  • local variables
  • parameter values
  • return addresses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly