1 / 7

Understanding Doubly Linked Lists in Data Structures (CSCI 132 Spring 2019)

This lecture introduces doubly linked lists, a critical data structure in computer science that allows for efficient insertion and deletion of nodes. Each node contains pointers to both its next and previous nodes, enabling bidirectional traversal. We discuss the implementation details, including the structure of nodes and the functions necessary for managing the list, such as setting positions. Additionally, we compare the advantages and disadvantages of linked lists versus contiguous lists, providing insights into when to use each type of structure.

stella
Download Presentation

Understanding Doubly Linked Lists in Data Structures (CSCI 132 Spring 2019)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data StructuresCSCI 132, Spring 2019Lecture 21Doubly Linked Lists

  2. Doubly Linked Lists Doubly linked lists have pointers to both the next node and the previous node in the list. The data members for this class would be: int count; mutable int current_position; mutable Node<List_entry> *current; entry 0 entry 1 entry 2 current

  3. Nodes for doubly linked lists template <class Node_entry> struct Node { //Data members Node_entry entry; Node<Node_entry> *next; Node<Node_entry> *back; //Constructors Node(); Node(Node_entry, Node<Node_entry> *link_back = NULL Node<Node_entry> *link_next = NULL); };

  4. set_position( ) for doubly linked lists template <class List_entry> void List<List_entry> :: set_position(int position) const // Set current to point to node at position specified in parameter { //we will fill this out in class. }

  5. Advantages of linked lists Advantages: Disadvantages:

  6. Linked vs. Contiguous lists Use contiguous lists when: Use linked lists when:

  7. Linked Lists in Arrays Store items in one array. Store "pointers" in a second, parallel array. Each "pointer" is the index of the next item in the list.

More Related