dis2

dis2 - CS32 Discussion Section 1B Week 3 TA: Brian Choi...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS32 Discussion Section 1B Week 3 TA: Brian Choi Reminder Project 2 Due 4/20 Tue. Tests your knowledge of Doubly Linked Lists Destructor, Copy Constructor, Assignment Operator Abstraction Make sure you comment your code and indent properly! Abstraction in CS Set class interface empty(), size(), insert(), contains(), Version 1 local array (HW1) Version 2 dynamic array (HW1) Version 3 doubly linked list (P2) Your code Set s; s.insert(5); abstraction barrier TV Analogy Universal Remote Control Buttons: power, vol up, vol down, 21 CRT TV 30 LCD TV 42 Plasma TV YOU abstraction barrier More Data Structures! Doubly Linked Lists Stacks Queues Debugging example Doubly Linked Lists Extension of singly linked lists we saw last week struct Node { int value; Node *next; Node *prev; }; head tail This tail pointer is optional, but doesnt make sense to use it without the tail pointer the advantage that doubly linked lists have over singly linked lists is that it lets you trace from behind. Insertion Before: After: head tail p head tail Insertion p->prev = NULL; p->next = head; head->prev = p; head = p; head tail p tail p head Insertion head tail p tail p head Does this work with an empty list (head == NULL)? p->prev = NULL; p->next = head; head->prev = p; head = p; Insertion p->prev = NULL; p->next = head; if (head != NULL) { head->prev = p; } head = p; if (tail == NULL) { tail = p; } head tail p Does this work with an empty list (head == NULL)? head p tail Insertion Just reverse the operations to append the new node to the tail of the list p->next = NULL; p->prev = tail; if (tail != NULL) { tail->next = p; } tail = p; If (head == NULL) { head = p; } Adding dummy (sentinel) nodes removes the need to...
View Full Document

This note was uploaded on 02/09/2012 for the course CS 32 taught by Professor Davidsmallberg during the Spring '08 term at UCLA.

Page1 / 38

dis2 - CS32 Discussion Section 1B Week 3 TA: Brian Choi...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online