61a lecture 18 announcements sequences the sequence
play

61A Lecture 18 Announcements Sequences The Sequence Abstraction 4 - PowerPoint PPT Presentation

61A Lecture 18 Announcements Sequences The Sequence Abstraction 4 The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. 4 The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. There isn't just one


  1. 61A Lecture 18

  2. Announcements

  3. Sequences

  4. The Sequence Abstraction 4

  5. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. 4

  6. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. There isn't just one sequence class or data abstraction (in Python or in general). 4

  7. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. There isn't just one sequence class or data abstraction (in Python or in general). The sequence abstraction is a collection of behaviors: 4

  8. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. There isn't just one sequence class or data abstraction (in Python or in general). The sequence abstraction is a collection of behaviors: Length . A sequence has a finite length. Element selection . A sequence has an element corresponding to any non-negative integer index less than its length, starting at 0. 4

  9. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. 0 , 1 , 2 , 3 , 4 , 5 , 6 . There isn't just one sequence class or data abstraction (in Python or in general). The sequence abstraction is a collection of behaviors: Length . A sequence has a finite length. Element selection . A sequence has an element corresponding to any non-negative integer index less than its length, starting at 0. 4

  10. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. 0 , 1 , 2 , 3 , 4 , 5 , 6 . There isn't just one sequence class or data abstraction (in Python or in general). The sequence abstraction is a collection of behaviors: Length . A sequence has a finite length. Element selection . A sequence has an element corresponding to any non-negative integer index less than its length, starting at 0. There is built-in syntax associated with this behavior, or we can use functions. 4

  11. The Sequence Abstraction red, orange, yellow, green, blue, indigo, violet. 0 , 1 , 2 , 3 , 4 , 5 , 6 . There isn't just one sequence class or data abstraction (in Python or in general). The sequence abstraction is a collection of behaviors: Length . A sequence has a finite length. Element selection . A sequence has an element corresponding to any non-negative integer index less than its length, starting at 0. There is built-in syntax associated with this behavior, or we can use functions. A list is a kind of built-in sequence 4

  12. Linked Lists

  13. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 6

  14. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 6

  15. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance first: 3 rest: 6

  16. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance first: 3 first: 4 rest: rest: 6

  17. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance first: 3 first: 4 first: 5 rest: rest: rest: 6

  18. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: 6

  19. Linked List Structure A linked list is either empty or a first value and the rest of the linked list A linked list is a pair 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: 6

  20. Linked List Structure A linked list is either empty or a first value and the rest of the linked list A linked list is a pair 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: The first (zeroth) element is an attribute value 6

  21. Linked List Structure A linked list is either empty or a first value and the rest of the linked list A linked list is a pair 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: The first (zeroth) The rest of the element is an elements are stored attribute value in a linked list 6

  22. Linked List Structure A linked list is either empty or a first value and the rest of the linked list A linked list A class attribute represents is a pair an empty linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: The first (zeroth) The rest of the element is an elements are stored attribute value in a linked list 6

  23. Linked List Structure A linked list is either empty or a first value and the rest of the linked list A linked list A class attribute represents is a pair an empty linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: The first (zeroth) The rest of the element is an elements are stored attribute value in a linked list Link(3, Link(4, Link(5, Link.empty))) 6

  24. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: , Link.empty ) Link(3, Link(4, Link(5 ))) 7

  25. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: , Link.empty ) Link(3, Link(4, Link(5 ))) 7

  26. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: , Link.empty ) Link(3, Link(4, Link(5 ))) 7

  27. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance Link.empty first: 3 first: 4 first: 5 rest: rest: rest: , Link.empty ) Link(3, Link(4, Link(5 ))) 7

  28. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance first: 3 first: 4 first: 5 rest: rest: rest: , Link.empty ) Link(3, Link(4, Link(5 ))) 7

  29. Linked List Structure A linked list is either empty or a first value and the rest of the linked list 3 , 4 , 5 Link instance Link instance Link instance first: 3 first: 4 first: 5 rest: rest: rest: Link(3, Link(4, Link(5 ))) 7

  30. Linked List Class Link(3, Link(4, Link(5 ))) 8

  31. Linked List Class Linked list class: attributes are passed to __init__ Link(3, Link(4, Link(5 ))) 8

  32. Linked List Class Linked list class: attributes are passed to __init__ class Link: Link(3, Link(4, Link(5 ))) 8

  33. Linked List Class Linked list class: attributes are passed to __init__ class Link: def __init__(self, first, rest=empty): Link(3, Link(4, Link(5 ))) 8

  34. Linked List Class Linked list class: attributes are passed to __init__ class Link: def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) Link(3, Link(4, Link(5 ))) 8

  35. Linked List Class Linked list class: attributes are passed to __init__ class Link: def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 ))) 8

  36. Linked List Class Linked list class: attributes are passed to __init__ class Link: def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Returns whether rest is a Link Link(3, Link(4, Link(5 ))) 8

  37. Linked List Class Linked list class: attributes are passed to __init__ class Link: def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof. Link(3, Link(4, Link(5 ))) 8

  38. Linked List Class Linked list class: attributes are passed to __init__ class Link: empty = () def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof. Link(3, Link(4, Link(5 ))) 8

  39. Linked List Class Linked list class: attributes are passed to __init__ class Link: Some zero-length sequence empty = () def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof. Link(3, Link(4, Link(5 ))) 8

Recommend


More recommend