Слайд 2

A stack is an ADT that might involve a dynamic or

A stack is an ADT that might involve a dynamic or

static implementation. A stack is a last-in-first-out (LIFO) or first-in-last-out (FILO) ADT. Implementations should include two operations, pushing and popping, and a pointer to the top of the stack.
Слайд 3

A real life example is a stack of books you might

A real life example is a stack of books you might

have on your desk:
CPT-ADT-stacks-real-life.svg
In this example we keep adding (pushing) books to the stack. If we want to get at the bottom book about Cars, we must first remove (pop) all the books above it. Hence First In Last Out (FILO)
Слайд 4

Let's take a look at a computer implementation of a stack:

Let's take a look at a computer implementation of a stack:

Pushing:

Adds a new specified item to the top of the stack
Popping: Removes the item from the top of the stack.
Слайд 5

Слайд 6

Stacks have several uses: Reversing queues (as seen above with the

Stacks have several uses:

Reversing queues (as seen above with the Alphabetised

names)
Performing Reverse Polish Calculations (see ....)
Holding return addresses and syste states for recursive function calls
Слайд 7

Exercise: Stacks Draw the stack after each of the following commands,

Exercise: Stacks

Draw the stack after each of the following commands, starting

with an empty stack. What does the stack achieve:
Push 'Annabelle'
Push 'Chris'
Push 'Hemingway'
Push 'James'
Pop
Pop
Pop
Pop
Слайд 8

Give the set of instructions required to get from State 1

Give the set of instructions required to get from State 1

to State 2 as shown below:

Exercise: Stacks

Слайд 9

Give the set of instructions required to get from State 1

Give the set of instructions required to get from State 1

to State 2 as shown below:

Exercise: Stacks

Answer:
Pop
Pop
Push 'Sand'
Push 'Witches'

Слайд 10

https://en.wikibooks.org/wiki/A-level_Computing/AQA/Paper_1/Fundamentals_of_data_structures/Stacks Exercise: Stacks

https://en.wikibooks.org/wiki/A-level_Computing/AQA/Paper_1/Fundamentals_of_data_structures/Stacks

Exercise: Stacks