CSE 250 Lecture 16: 3.6.17 lecture 16 Lists

46 views2 pages

Document Summary

A list is represe(cid:374)ted as a poi(cid:374)ter (cid:272)alled (cid:862)head(cid:863) to the first ele(cid:373)e(cid:374)t. Node* head ---> 15 --> 22 --> 47 --> 5 --> (empty) If we want to compute a function on a list, > 15 -> 22 -> 47 -> 5 -> . Build a list: (nullptr means empty list) //(cid:374)eed (cid:374)e(cid:449) te(cid:373)p (cid:271)e(cid:272)ause other(cid:449)ise (cid:449)e"d loop (cid:271)a(cid:272)k to the first ele(cid:373)e(cid:374)t head temp -> 47 -> 5 -> . Node* head = nullptr; head = new node(); head. value = 5; head. next = nullptr; Node* temp = new node(); temp. value = 47; temp. next = head; head = temp; head = new node(); head. value = 22; head. next = head; temp = head; head = new node(); head. value = 15; head. next = temp; If i keep a pointer to the end of the list, we can get o(1) insertion at end head. 15 -> 22 -> 47 -> 5 -> head temp.

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