CS321B_week3 - CS32 Discussion Section 1B Week 3 TA Hao...

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

View Full Document Right Arrow Icon
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
Image of page 1

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

View Full Document Right Arrow Icon
Reminder & Agenda Discussion Slides http://cadlab.cs.ucla.edu/~cody/cs32 / Linked List Doubly Linked List 1 st Midterm next Thursday Project 2 due next Tuesday 9:00 p.m.
Image of page 2
Linked Lists Component Node value can be any kind of data variables/structures next points to either the next Node or null Example value *next typedef int ItemType; struct Node { ItemType value; Node *next; };
Image of page 3

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

View Full Document Right Arrow Icon
Linked Lists Single linked lists Are we done? value *next value *next value *next null NO!!
Image of page 4
Linked Lists You have to know where it begins We call it head pointer Node *head; value *next value *next value *next null
Image of page 5

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

View Full Document Right Arrow Icon
Linked Lists Check list A description of a node with a next pointer A head pointer points to the first node The list must be loop-free Unless it is a circularly linked list
Image of page 6
Linked Lists Operations Search Insert Remove Sanity Check!!
Image of page 7

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

View Full Document Right Arrow Icon
Linked Lists (Search) Simply traverse the linked list 1 *next 12 *next LinkedList::search( int expect) { Node *currNode = head; if (currNode == null) return null; while (currNode->next != null) { if (currNode->value == expect) return currNode; currNode = currNode->next; } return null; } null
Image of page 8
Linked Lists (Insert) 1. New a node 12 *next null Node *newNode = new Node; newNode->value = 12; newNode->next = null;
Image of page 9

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

View Full Document Right Arrow Icon
Linked Lists (Insert) 1. New a node 2. Fine the tail 1 *next 4 *next Node *currNode = head; while (currNode->next != null) currNode = currNode- >next; null
Image of page 10
Linked Lists (Insert) 1. New a node 2. Fine the tail 3. Link the new node and the tail 12 *next null 1 *next 4 *next currNode->next = newNode;
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
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