CSC 216/s08/wholesome discipline: Difference between revisions
m (quick formatting fix) |
No edit summary |
||
Line 3: | Line 3: | ||
===The problem=== | ===The problem=== | ||
In this exercise, students will learn the difference between stacks and queues, mainly which end to push and pop from. In a stack, the items are added and removed from the top of a stack (LIFO); where as in a queue the items are added to the end and removed from the front (FIFO). | In this exercise, students will learn the difference between stacks and queues, mainly which end to push and pop from. In a stack, the items are added and removed from the top of a stack (LIFO); where as in a queue the items are added to the end and removed from the front (FIFO). | ||
===Participants and props=== | ===Participants and props=== | ||
Line 11: | Line 11: | ||
===The script=== | ===The script=== | ||
Each participant will be given a plate to | Each participant will be given a plate to write their name on, and will then stack them in a pile (Push). Afterwards, a certain name will have to be found, and the only way to get to it will be by taking off the top plate (Pop), until the desired name is found. This demonstrates the Last In First Out concept of a stack. | ||
Afterwards, a certain name will have to be found, and the only way to get to it will be by taking off the top | |||
plate (Pop), until the desired name is found. This demonstrates the | |||
Then another group of students will demonstrate how queues work. Each student will line up to get a | Then another group of students will demonstrate how queues work. Each student will line up to get a piece of candy. The first person to line up will be in the front and everyone else in the line will line up behind him (Push). Once the first person gets his piece of candy and leaves (Pop), the next person in line will then be able to get a piece of candy (which will most definitely raise class participation). This demonstrates the First In First Out concept of a queue. | ||
piece of candy. The first person to line up will be in the front and everyone else in the line will line up | |||
behind him (Push). Once the first person gets his piece of candy and leaves (Pop), the next person in line | |||
will then be able to get a piece of candy. | |||
After having done the exercise, give some examples of where queues and stacks are used in real programming. For example, stacks are used to keep track of method calls. Queues are used whenever using a buffer, or keeping track of things to do. |
Latest revision as of 21:20, 23 April 2008
Stacks & Queues
The problem
In this exercise, students will learn the difference between stacks and queues, mainly which end to push and pop from. In a stack, the items are added and removed from the top of a stack (LIFO); where as in a queue the items are added to the end and removed from the front (FIFO).
Participants and props
For this exercise about seven students will be needed to act as objects. The props will be plates, and candy.
The script
Each participant will be given a plate to write their name on, and will then stack them in a pile (Push). Afterwards, a certain name will have to be found, and the only way to get to it will be by taking off the top plate (Pop), until the desired name is found. This demonstrates the Last In First Out concept of a stack.
Then another group of students will demonstrate how queues work. Each student will line up to get a piece of candy. The first person to line up will be in the front and everyone else in the line will line up behind him (Push). Once the first person gets his piece of candy and leaves (Pop), the next person in line will then be able to get a piece of candy (which will most definitely raise class participation). This demonstrates the First In First Out concept of a queue.
After having done the exercise, give some examples of where queues and stacks are used in real programming. For example, stacks are used to keep track of method calls. Queues are used whenever using a buffer, or keeping track of things to do.