λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

University of California, Berkeley/ElectricalEngineering & ComputerSciences

(48)
Linked Lists & Mutable Trees Linked Lists Linked List Definition A Linked List is either : - Empty - Composed of a first element and the rest of the linked list Creating Linked Lists : We’ll define a linked list recursively by making a constructor that takes in a first and rest value The Link Class Processing Linked Lists - Sum Goal : Given a linked list, lnk, return the sum of all elements in the linked list - display_link..
Inheritance Re-Implement Rationals : Rational Class - Attributes: Numerator Denominator - Methods: print ( ) - should print ‘numerator / denominator’ add ( other ) - should return a new rational with addition of current and other mul ( other ) - should return a new rational with multiplication of current and other Inheritance Class Relationships : Electric-type Pokemon are simply specialized versions of reg..
Objects Object-Oriented Programming Why OOP? - A (hopefully) more intuitive way of representing data - A common method for organizing programs - Formally split "global state" and "local state" for every object Classes - Every object is an instance of a class - A class is a type or category of objects - A class serves as a blueprint for its instances The Class Statement : Class Statements defines the blu..
Week 5 https://sequoia-tree.github.io/TEMPORARY/Objects.pdf http://www.tmmydngyn.me/cs61a/guides/oop.html Object Oriented Programming Information about inheritance will be added soon! Basics So far in this course we’ve been writing programs using functions and built-in data types. We’ve also created our own abstract data types (such as the link and tree ADTs). Recall that ADTs use constr www.tmmydngyn...
(Higher-Order) Functions, Sequences, Recursion and TreeRecursion, Trees ( Higher - Order ) Functions Functions : a function is made up of a series of statements, and takes in an input and maps it to an output How we descrive functions : - domain : the set of possible inputs a function may take in - range : the set of possible output values a function may return - behavior : the relationship between input and output EXAM _ pay close attention to the specified domain ..
Iterators & Generators Iterators & Generators Definitions - Lazy evaluation : delays evaluation of an expression until its value is needed - Iterable : an ovject capable of returning its members one at a time. examples include all sequences ( string, list )and some non-sequence types ( dictionaries ) - Iterator : an object that provide sequenctial access to values, one by one ( all iterators are iterables. not all ite..
LAB_day 6 Nonlocal def g(x) : def f(): x = 10 x = x + 2 f() print(x) g(20) def g(x): def f(): x = x - 8 f() print(x) g(20) By default, - you can access variables in parent frames - you cannot modify variables in parent frames nonlocal statements allow you to modify a name in a parent frame instead of creating a new binding in the current frame
Mutable Functions & Growth Mutable Values Identity vs. Equality in Environment Diagrams - Review : For assignment statements, evaluate the right side, then assign to the left - Copying : When creating a copy, copy exactly what's "in the box" Mutating Within Functions Mutable Functions Functions with behavior that changes over time : returns the same value when called with the same input : return values are different when ..