CSC 216/s08/wholesome discipline: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 2 users not shown)
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===


For this exercise about seven students will be needed to act as objects. The props will be plates, and candy.
For this exercise about seven students will be needed to act as objects. The props will be plates, and candy.


===The script===
===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.
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. This demonstrates the First in First out concept of a queue.
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.


*side note the promise of candy will most definitely raise class participation.
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.