Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.

Slides:



Advertisements
Similar presentations
Linked List Variations
Advertisements

Data Structure Lecture-5
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Review Learn about linked lists
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Data Structures: A Pseudocode Approach with C
Data Structures & Algorithms
Comparison summary Array based (dynamic) Keeps place for up to 4N elements Each element takes 1 memory places Fast accession time Slow removals and insertion.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
Arrays & Linked Lists Last Update: Aug 21, 2014EECS2011: Arrays & Linked Lists1.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Data Structures Using C++1 Chapter 5 Linked Lists.
CS2006- Data Structures I Chapter 5 Linked Lists III.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
COMPSCI 105 SS 2015 Principles of Computer Science
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
1 What is a Circular Linked List? l A circular linked list is a list in which every node has a successor; the “last” element is succeeded by the “first”
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
CPSC 252 Linked Lists III Page 1 Variations on Singly Linked Lists Inserting or deleting at the front of a list is different from at any other point in.
One implementation of the LIST ADT Insert new node before current and new node becomes current (assume new node created) node newNode = new node; head.
Lecture 6 of Computer Science II
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
UNIT – I Linked Lists.
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Linked List Stacks, Linked List Queues, Dequeues
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
Doubly Linked List Review - We are writing this code
UNIT-3 LINKED LIST.
Problems with Linked List (as we’ve seen so far…)
Linked List Variations
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
Algorithm for deleting a node from a singly linked list
EEL 4854 IT Data Structures Linked Lists
ENERGY 211 / CME 211 Lecture 12 October 17, 2008.
Linked Lists head One downside of arrays is that they have a fixed size. To solve this problem of fixed size, we’ll relax the constraint that the.
Linked Lists with Tail Pointers
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use.
Doubly linked lists.
LINKED LISTS CSCD Linked Lists.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Evaluation of List Implementations
Circularly Linked Lists
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Doubly Linked Lists or Two-way Linked Lists
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Linked Lists with Tail Pointers
Doubly Linked List Implementation
Recursive Linked Lists
Linked Lists Chapter 4.
Problem Understanding
Chapter 17: Linked Lists.
LINKED LISTS.
Lecture 16 Section 6.2 Thu, Mar 1, 2007
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
CS148 Introduction to Programming II
Recursive Linked Lists
Recursive Linked Lists
BY PROF. IRSHAD AHMAD LONE.
Chapter 9 Linked Lists.
Problem Understanding
Presentation transcript:

Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006

Topics Doubly Linked Lists Doubly Linked List Nodes Validity Requirements Inserting and Deleting

Doubly Linked Lists A doubly linked list is a linked list in which each node has two links A forward pointer to its successor A backwards pointer to its predecessor.

Doubly Linked List Nodes A DoublyLinkedListNode has three data members: T data - Value stored in the node. DoublyLinkedListNode* prev - Pointer to the previous node. DoublyLinkedListNode* next - Pointer to the next node.

The Data Members A DoublyLinkedList object has three data members: int size - Number of elements in the list. DoublyLinkedListNode* head - Pointer to the first node. DoublyLinkedListNode* tail - Pointer to the last node.

Chasing Pointers We can move both forwards and backwards in the list. When chasing pointers, it is not necessary to keep a pointer to the previous node.

Validity Requirements size >= 0. If size == 0, then head == NULL tail == NULL If size >= 1, then head != NULL tail != NULL

Validity Requirements If size == 1, then head == tail If size >= 1, then The next pointer in node size is NULL. The prev pointer in node 1 is NULL.

Validity Requirements If size >= 2, then For every i from 1 to size - 1, the next pointer in node i is not NULL. For every i from 2 to size, the prev pointer in node i is not NULL. The prev pointer of node 2 equals head. The next pointer of node size - 1 equals tail.

Validity Requirements If size >= 3, then For every i from 2 to size - 1, the next pointer of node i - 1 equals the prev pointer of node i + 1.

Inserting into a Doubly Linked List Locate the position for the insertion. Create the new node. Update the forward pointers. Update the backward pointers. Increment the size of the list. Do we need both the prev and curr pointers?

Deleting from a Doubly Linked List Locate the position for the deletion. Update the forward pointer. Update the backward pointer. Delete the node. Decrement the size of the list.

The DoublyLinkedList Class Example doublylinkedlistnode.h doublylinkedlist.h ListTest.cpp