10_linked_lists_I - CSCI-1200 Data Structures - Fall 2010...

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

View Full Document Right Arrow Icon
CSCI-1200 Data Structures — Fall 2010 Lectures 10 — Linked Lists, Part I Review from Lecture 9 Returning references to member variables from member functions Review of iterators and iterator operations STL Lists, erase and insert on lists Differences between indices and iterators, differences between lists and vectors template <class T> class Node { public: T value; Node* ptr; }; NULL value ptr value ptr value ptr value ptr head Stepping through a list template <class T> for (Node<T> *p = head; p != NULL ; p = p->ptr) { if (p->value == x) return true; } return false; } Push back template <class T> // test for empty list if (head == NULL) { Node<T> *q = new Node<T>; q->value = value; q->ptr = NULL; head = q; } else { Node<T> *p = head; for ( ; p->ptr != NULL ; p = p->ptr) { // do nothing, just walk to the end of the list } Node<T> *q = new Node<T>; q->value = value; q->ptr = NULL; p->ptr = q; } } STL List w/ iterators vs. Today’s Lecture Common mistakes Limitations of singly-linked lists Doubly-linked lists: Structure Insert Remove
Background image of page 1

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

View Full DocumentRight Arrow Icon
11.1 Basic Mechanisms: Inserting a Node There are two parts to this: finding the location where the insert must take place, and doing the insert operation. We will ignore the find for now. We will also write only a code segment to understand the mechanism rather than writing a complete function. The insert operation itself requires that we have a pointer to the location before the insert location.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2012 for the course CSCI 1200 taught by Professor Cutler during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 5

10_linked_lists_I - CSCI-1200 Data Structures - Fall 2010...

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

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