10-linked_list - CSE 143 Lecture 10 Linked List Basics...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143 Lecture 10 Linked List Basics reading: 16.1 - 16.2 slides created by Marty Stepp http://www.cs.washington.edu/143/
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 References vs. objects variable = value ; a variable (left side of = ) is an arrow (the base of an arrow) a value (right side of = ) is an object (a box; what an arrow points at) • For the list at right: – a.next = value ; means to adjust where points variable = a.next; means to make variable point at 10 next data a 20 next data 1 2 1 2
Image of page 2
3 Reassigning references • when you say: – a.next = b.next; • you are saying: "Make the variable a.next refer to the same value as b.next ." Or, "Make a.next point to the same place that b.next points." 10 next data a 20 next data 30 next data b 40 next data
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Linked node question • Suppose we have a long chain of list nodes: We don't know exactly how long the chain is. • How would we print the data values in all the nodes? 10 next data 990 next data list ... 20 next data
Image of page 4
5 Algorithm pseudocode • Start at the front of the list. • While (there are more nodes to print): Print the current node's data . Go to the next node. • How do we walk through the nodes of the list? list = list.next; // is this a good idea? 10 next data 990 next data list ... 20 next data
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Traversing a list?
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern