Class Notes (834,541)
Canada (508,588)
CSC148H1 (92)
Paul Gries (18)
Lecture

march19c.docx

2 Pages
100 Views
Unlock Document

Department
Computer Science
Course
CSC148H1
Professor
Paul Gries
Semester
Winter

Description
 Recursive structures o Recursion definition: Any structure or function whose definition involves smaler versions of the same structure or function. o Remember that recursion doesn’t just mean functions that call themselves, but can extend to data structures as well Typical List Recurisve List  Recursive list syntax 1. class Node(object): 2. „„„A list node containing data and a reference 3. to the next Node.‟‟‟ 4. 5. def __init__(self, data): 6. „„„Create a Node containing data, with no 7. reference to a next Node.‟‟‟ 8. 9. self.data = data 10. self.next = Non o for longer strings  accessing elements of a linked list involves traversing through the links >>> front = Node(“Once”) >>> words = “To be or not to be”.split() >>> front.next = Node(“upon”) >>> front = None >>> front.next.next = Node(“a”) >>> for word in words: >>> front.next.next.next = Node(“time”) >>> temp = Node(word) >>> front.data >>> temp.next = front >>> front = temp  Removing from a linked list: o To remove a node, you must have a reference to the node immediately before it. o Need to consider special cases: removing the first element, removing elements that aren’t in the list 1. def rem
More Less

Related notes for CSC148H1

Log In


OR

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