CSC148H1 Lecture Notes - Lecture 6: Linked List, Mutation

22 views5 pages
13 Nov 2017
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

We ha(cid:448)e (cid:374)o(cid:449) spe(cid:374)t so(cid:373)e ti(cid:373)e (cid:449)riti(cid:374)g (cid:373)ethods (cid:449)hi(cid:272)h tra(cid:448)erse a li(cid:374)ked list. Here"s a re(cid:373)i(cid:374)der of the basic traversal pattern using a while loop: understanding this is critical before moving on! curr = my_linked_list. _first while curr is not none: All of the methods we looked at last time were non-(cid:373)utati(cid:374)g, (cid:373)ea(cid:374)i(cid:374)g the(cid:455) did(cid:374)"t (cid:272)ha(cid:374)ge the li(cid:374)ked list. We started (cid:449)ith the(cid:373) (cid:271)e(cid:272)ause the(cid:455)"re ge(cid:374)erall(cid:455) easier to u(cid:374)dersta(cid:374)d tha(cid:374) their (cid:373)utati(cid:374)g (cid:272)ousi(cid:374)s. This (cid:449)eek, (cid:449)e"re goi(cid:374)g to look at the t(cid:449)o (cid:373)ajor mutating operations on linked lists: inserting and deleti(cid:374)g ite(cid:373)s at a parti(cid:272)ular i(cid:374)de(cid:454) i(cid:374) the list. Before (cid:449)e start, let"s re(cid:373)i(cid:374)d oursel(cid:448)es ho(cid:449) these operations behave for built-in python lists: Suppose we want to insert an item called item into our linked list at position index. Update the links of the (index-1)-th and new node to insert the new node in the list.

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