Here is a direct link to Snap!
To play with Snap! you can just click on the play button on some of the images, like the one above. If you have any problems with it loading, visit Snap! directly in a new browser tab (On that page, click "Run Snap! now"). Another possible solution, if your browser is not Chrome, is to give Chrome a try.
A value is anything we can have in a universe, and a type is the kind of that thing. We use types to classify the kinds of things we can have.
For example, in this Snap! universe, one kind of type is
We can see another example of values and types in the figure above. That's right: values such as "what?" or "are you kidding?" belong to a type called
Can you see another example of a type there? You got it!
is an example of the list type.
In fact, every sprite we create represents a value, as well as a type! Why a type? Remember? Because each sprite is also a prototype and we can make many clones (new values) from it! Here is our own
We make a shopping list when we need to go shopping. We call it a list but it's more than a list, is't it? Is it a set then? Again, it's more than that, because other than saying what we need, it usually tells us how much of each item we need:
In programming we have a different type name for these: a
A dictionary is one-to-one relation between values of one type, and values of another type. For example, we can say about the shopping list figure above that it is a dictionary which takes values of type
Like any other data structure, a dictionary has a set of operations. The main ones are typically called
What do you think should happen if we look up something that is not in the dictionary, for example asking for Apples? That' right! You will just get nothing!
In this exercise we will make a dictionary in Snap!. I started this for you. Clicking on the pencil should do
Here is a direct link to this exercise.
A Stack is another kind of a data structure, very similar to the List. Instead of list's
Think of a stack of dishes in your kitchen cabinet. You normally pick up the top one (
When we did the List example in last class, the
Open up the list example, shown again below, and see if you can modify some of the scripts to turn it into a stack!
Here is a direct link to this exercise.
Congrats! Now you have a working stack. Save your work on your computer.
Next: Class 10: Graphs, An Algorithm
Previous: Class 8: Binary Search Trees
Back to: Table of Contents