dis2

dis2 - CS32 Discussion Sec.on 3A 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 Sec.on 3A Week 3 TA: Brian Choi Reminder Project 2 Due 1/27 Tue Tests your knowledge of Doubly Linked Lists Destructor, Copy Constructor, Assignment Operator Abstrac.on Abstrac.on 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; sinsert(5); abstraction barrier TV Analogy Universal Remote Control BuYons: power, vol up, vol down, 21 CRT TV 30 LCD TV 42 Plasma TV OU abstraction barrier More Data Structures! Doubly Linked Lists Stacks Queues 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. Inser.on Before: Aber: head tail p head tail Inser.on p>next = head; head>prev = p; head = p; head tail p tail p head Inser.on p>next = head; head>prev = p; head = p; head tail p tail p head Does this work with an empty list (head == NULL)? Inser.on 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 Inser.on Just reverse the opera.ons to append the new node to the tail of the list p>prev = tail; if (tail != NULL) tail>next = p; tail = p; If (head == NULL) head = p; Adding dummy (sen.nel) nodes removes the need to deal with empty lists by keeping at least one (or two) node in the list at all .mes More to come Search...
View Full Document

This note was uploaded on 11/07/2009 for the course CS 32 taught by Professor Davidsmallberg during the Winter '08 term at UCLA.

Page1 / 38

dis2 - CS32 Discussion Sec.on 3A 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