61a lecture 22 announcements linked lists recursive lists
play

61A Lecture 22 Announcements Linked Lists Recursive Lists Can - PowerPoint PPT Presentation

61A Lecture 22 Announcements Linked Lists Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link 4 Recursive Lists Can Change Attribute assignment statements can change first and rest


  1. 61A Lecture 22

  2. Announcements

  3. Linked Lists

  4. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link 4

  5. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list 4

  6. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) 4

  7. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) Global frame First Rest First Rest First Rest 1 2 3 s 4

  8. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) Global frame First Rest First Rest First Rest 1 2 3 s Note: The actual environment diagram is much more complicated. 4

  9. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) Note: The actual environment diagram is much more complicated. 4

  10. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 Note: The actual environment diagram is much more complicated. 4

  11. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest Note: The actual environment diagram is much more complicated. 4

  12. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s Note: The actual environment diagram is much more complicated. 4

  13. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s >>> s.first Note: The actual environment diagram is much more complicated. 4

  14. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s >>> s.first 5 Note: The actual environment diagram is much more complicated. 4

  15. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s >>> s.first 5 >>> s.rest.rest.rest.rest.rest.first Note: The actual environment diagram is much more complicated. 4

  16. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s >>> s.first 5 >>> s.rest.rest.rest.rest.rest.first 2 Note: The actual environment diagram is much more complicated. 4

  17. Recursive Lists Can Change Attribute assignment statements can change first and rest attributes of a Link The rest of a linked list can contain the linked list as a sub-list >>> s = Link(1, Link(2, Link(3))) >>> s.first = 5 >>> t = s.rest >>> t.rest = s >>> s.first 5 >>> s.rest.rest.rest.rest.rest.first 2 Global frame First Rest First Rest Note: The actual 5 2 s environment diagram is much more complicated. t 4

  18. Environment Diagrams

  19. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): nonlocal bear if bear(berk) == 0: Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  20. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear if bear(berk) == 0: Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  21. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear if bear(berk) == 0: Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  22. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] if bear(berk) == 0: Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  23. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  24. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  25. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  26. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal [parent=f1] bear = lambda ley: berk-ley return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  27. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal [parent=f1] bear = lambda ley: berk-ley berk 2 return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  28. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): func λ (ley) [parent=f2] f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal [parent=f1] bear = lambda ley: berk-ley berk 2 return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  29. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): func λ (ley) [parent=f2] f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal [parent=f1] bear = lambda ley: berk-ley berk 2 return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

  30. Go Bears! Global frame def oski(bear): func oski(bear)[parent=G] oski def cal(berk): func λ (ley) [parent=f2] f1: oski [parent=G] nonlocal bear bear func abs(...) [parent=G] cal if bear(berk) == 0: func cal(berk) [parent=f1] Return Value return [berk+1, berk-1] f2: cal [parent=f1] bear = lambda ley: berk-ley berk 2 return [berk, cal(berk)] Return Value return cal(2) oski(abs) Return Value Return Value 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend