CSC148H1 Lecture Notes - Linked List, 1.-Class Torpedo Boat, Iter

62 views3 pages
11 Jan 2013
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

1. class linkedlist(object): class node(object): def __init__(self, val): self. data = val self. next = none def __init__(self): """a new empty linked list. """ self. contents = none def insert(self, v, i): Insert v at index i into this list. """ # find the node that i want to insert *after*. if i == 0: n = linkedlist. node(v) n. next = self. contents self. contents = n else: # find the previous node. t = self. contents for k in range(i - 1): t = t. next n = linkedlist. node(v) n. next = t. next t. next = n def append(self, v): Append v to the end of this list. """ self. insert(v, len(self)) def get(self, i): Return the item at index i. """ t = self. contents for k in range(i): t = t. next return t. data def remove(self, i): # find the start. t = self. contents for k in range(start): t = t. next. # gather the items in the slice. for i in range(stop - start): res. append(t. data) t = t. next return res def __setitem__(self, i, v):

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

Related Questions