Class Notes (784,738)
Canada (481,326)
CS 234 (31)
Lecture

notes09a.pdf

3 Pages
79 Views
Unlock Document

School
University of Waterloo
Department
Computer Science
Course
CS 234
Professor
Robert Sproule
Semester
Summer

Description
ADT Sequence Data: Linear collection of items Operations: Sequence() __repr__, __get_item__, __len__, append, insert, extend, pop, remove, reverse Linked list implementation of ADT sequence Fields: _head; of type Node, referencing the first item in the sequence _len; of type int*>=0+, storing the number of items in the sequence Implementing the “Basic” Operations Class Sequence: def __init__(self): S = Sequence() self._head = None len(s) self._len = 0 S*2+ def __len__(self): return self._len def getitem__(self, index): i = 0 curNode = self._head while curNode != None and 1 < index: curNode = curNode.next i += 1 return curNode.item def __repr__(self): seq = ‘*‘ curNode = self._head while curNode != None seq += str(curNode.item) + ‘,’ curNode = curNode.next return seq + ‘+’ Adding to the sequence def append(self, x): if self._head == None: self._head = Node(x) else: curNode = self._head while curNode.next != None: curNode = curNode.next curNode.next = Node(x) self._len += 1 def insert(self, index, item): if index == 0: self._head = Node(item, self._head) else: curNode = self._head for i in range(index - 1): curNode = curNode.next curNode.next = Node(item, curNode.next)
More Less

Related notes for CS 234

Log In


OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.

Submit