diff --git a/assets/pdfs/c88c-mt-study-guide.pdf b/assets/pdfs/c88c-mt-study-guide.pdf new file mode 100644 index 000000000..984f8540a Binary files /dev/null and b/assets/pdfs/c88c-mt-study-guide.pdf differ diff --git a/assets/slides/16-Data_Examples_1pp.pdf b/assets/slides/16-Data_Examples_1pp.pdf new file mode 100644 index 000000000..3c411266d Binary files /dev/null and b/assets/slides/16-Data_Examples_1pp.pdf differ diff --git a/assets/slides/16.py b/assets/slides/16.py new file mode 100644 index 000000000..5d9b34019 --- /dev/null +++ b/assets/slides/16.py @@ -0,0 +1,95 @@ +from link import * + + +def length(s): + """Return the number of elements in linked list s. + + >>> length(Link(3, Link(4, Link(5)))) + 3 + """ + if s is Link.empty: + return 0 + else: + return 1 + length(s.rest) + +def length_iter(s): + """Return the number of elements in linked list s. + + >>> length_iter(Link(3, Link(4, Link(5)))) + 3 + """ + k = 0 + while s is not Link.empty: + s, k = s.rest, k + 1 + return k + +def append(s, x): + """Append x to the end of non-empty s and return None. + + >>> s = Link(3, Link(4, Link(5))) + >>> append(s, 6) + >>> print(s) + <3 4 5 6> + """ + if s.rest: + append(s.rest, x) + else: + s.rest = Link(x) + +def append_iter(s, x): + """Append x to the end of non-empty s and return None. + + >>> s = Link(3, Link(4, Link(5))) + >>> append_iter(s, 6) + >>> print(s) + <3 4 5 6> + """ + while s.rest: + s = s.rest + s.rest = Link(x) + + +def pop(s, i): + """Remove and return element i from linked list s for positive i. + + >>> t = Link(3, Link(4, Link(5, Link(6)))) + >>> pop(t, 2) + 5 + >>> pop(t, 2) + 6 + >>> pop(t, 1) + 4 + >>> t + Link(3) + """ + assert i > 0 and i < length(s) + for x in range(i-1): + s = s.rest + result = s.rest.first + s.rest = s.rest.rest + return result + + +def range_link(start, end): + """Return a Link containing consecutive integers from start to end. + + >>> range_link(3, 6) + Link(3, Link(4, Link(5))) + """ + if start >= end: + return Link.empty + else: + return Link(start, range_link(start + 1, end)) + +def range_link_iter(start, end): + """Return a Link containing consecutive integers from start to end. + + >>> range_link_iter(3, 6) + Link(3, Link(4, Link(5))) + """ + s = Link.empty + k = end - 1 + while k >= start: + s = Link(k, s) + k -= 1 + return s diff --git a/index.html b/index.html index c6ab43840..3a550586c 100644 --- a/index.html +++ b/index.html @@ -148,6 +148,37 @@
The Midterm is Wednesday 10/30 8pm-10pm.
+ +The Ants project is due Wednesday 11/20 @ 11:59pm.
+ +