COMPSCI 61A Lecture Notes - Lecture 20: Mutation, Linked List
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
Set literals are enclosed in braces, but no colons. Duplicate elements are removed on construction no duplicates. Sets have arbitrary order, just like dictionaries. S = {3, 2, 1, 4, 4} Once you have a set, add element with . add(element) What we should be able to do with a set. Membership testing: is a value an element of a set. Union: return a set with all elements in set1 or set2. Intersection: return a set with any elment in set1 and set2. Adjoin : return a set with all elements in s and a value v. Doesn"t change original, creates new set and adds new one. Proposal 1: a set is alinked list taht contains no duplicates. Make sets ordered so that we can improve our order of growth. Implement set operations ordered linked lists, first, rest, == Def contains(s, v): if empty(s) or s. first > v: