lecture04 - Linked Lists, Queues, Stacks You've probably...

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

View Full Document Right Arrow Icon
1 Linked Lists, Queues, Stacks You’ve probably seen most of this, so let’s breath for a while Chapter 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 The linked list This is an data structure… Dynamically allocated nodes Each node has: Data (payload) Pointer to next node
Background image of page 2
3 Example template<class T> class CLinkedList { private: // This is the nested class for a linked list node. class Node { public: friend class iterator; friend class CLinkedList; // Most commonlly used constructor for a node. .. Node(const T &p) {m_payload = p; m_next = 0;} private: T m_payload; iterator m_next; }; ~cse331/Examples/LinkedList
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 What do we keep track of… Head pointer? Tail pointer? Head node?
Background image of page 4
5 Doubly linked lists Each node has a link to next and previous Why? What can we do now we could not do before? Head A X W Sometimes called a
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 InsertBefore for doubly linked list InsertBefore(x, b) x.next = b x.prev = b.prev x.next.prev = x x.prev.next = x Assumes a circular list What if not?
Background image of page 6
7 Operations on linked lists
Background image of page 7

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

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

This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

Page1 / 15

lecture04 - Linked Lists, Queues, Stacks You've probably...

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

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