CP164 Lecture Notes - Lecture 7: Init, Iterator, Nth Metal

439 views24 pages
1 Aug 2018
School
Course
Professor

Document Summary

__updated__ = 2018-03-21 from copy import deepcopy class _listnode: def __init__(self, value, next_): Initializes a list node that contains a copy of value and a link to the next node in the list. self. _data = deepcopy(value) self. _next = next_ return class list: def __init__(self): Initializes an empty list. self. _front = none self. _count = 0 return def empty(self): True if the list is empty, false otherwise. return self. _front is none def is_empty(self): True if the list is empty, false otherwise. return self. _front is none def __len__(self): Postconditions: returns the number of values in the list. return self. _count def insert(self, i, value): Inserts a copy of value into the list at index i. Preconditions: i - index value (int) value - a data element (?) Postconditions: a copy of value is added to index i, all other values are pushed right. If i outside of range of length of list, appended to end if i < 0:

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents