Dear Citizens of the World,
The 4th lecture of CSC148 touched upon Containers, Stacks, Sacks, Unittest, Balanced Paranthesis, and introduced us to Linked Lists.
The professor started off giving us useful definitions of Stacks and Sacks, metaphors to help us understand how they each work, and small bits of information on each data type.
A stack is made up of items of different sorts. The newest items added are placed on top of the stack and the oldest/first items added are placed on the bottom. Stacks are referred to as a LIFO structure which stands for Last In, First Out.
We are also told that we should not try to remove an item from an empty stack. We need to first know whether the stack is empty or has one or more items in it.
Metaphor: A stack of items is like a stack of dishes, the first dish placed on the counter will be the last to be used. This is because there are more dishes above it that need to be used first, and attempting to get a dish from the middle or bottom will cause all the dishes to fall and shatter - resulting in an error.
A sack also contains items of various types, but any new items are placed in a random place in the sack. This means any items removed will come out in a random order as well. Just like a stack we have to see first if the sack is empty or not.
Metaphor: This is similar to a person placing items in their backpack or purse. The items will change location i.e. a sweater might find its way to the bottom of the bag though it was the last thing to be placed inside the backpack.
There are similar traits between a stack and a sack, especially when it comes to use in client code:
s.__init__()
s.__str__()
s.__eq__()
s.add()
s.remove()
s.is_empty()
These traits can be managed in a superclass called Container!
While developing Container we have to look at the previously mentioned methods. Which ones should or should not be implemented?
This decision is dependent on each individual project. The methods used have to suit the projects needs.
To test everything we use Unittest.
Unittest allows us to create test cases, and use these test cases to, well, test. The test cases run independently, and everything is documented and reusable if ever needed again.
unittest.TestCase is not different from extending any other class. A subclass is created and special methods are over ridden.
Balanced Parentheses:
The opening and closing parentheses must match up in many situations. Matching means a opening parentheses followed by a closing parentheses or no parentheses present at all.
Examples of proper formatting:
17 + 5
(34234 * b * h)
Examples of improper formatting:
(3
)m
apple)
)unicorn(
Linked Lists:
Linked list nodes keep enough memory for the object value they want to use, a reference to and a reference to the node that will come next in the list.
Linked Lists are at the moment being implemented as nodes with a value and reference to any like objects.
In all honesty I wish a bit more of an explanation was given on Unittest, Container, and Linked Lists, but only so much can be fit into one lecture, which is unfortunate.
No comments:
Post a Comment