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.

Slides:



Advertisements
Similar presentations
Linked List Alternate approach to maintaining an array of elements Rather than allocating one large group of elements, allocate elements as needed Q: how.
Advertisements

Linked Lists Mohammed Almashat CS /03/2006.
Stacks, Queues, and Linked Lists
Linked Lists.
Linear Lists – Linked List Representation
DATA STRUCTURES USING C++ Chapter 5
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
LIST PROCESSING.
CHP-5 LinkedList.
Linked List Variations
CSCI2100B Linked List Jeffrey
Data Structure Lecture-5
Doubly-linked list library.
Data Structures: Doubly Linked List1 Doubly linked list l The linear linked list is accessed from the first node each time we want to insert or delete.
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.
Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
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.
Chapter 3: Arrays, Linked Lists, and Recursion
Chapter 17 Linked List.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Last meeting..Doubly Linked List  InsertToFront  InsertToEnd  Search  DeleteNode.
Data Structures Using Java1 Chapter 4 Linked Lists.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 11 – Data Structures.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Data Structures Using C++1 Chapter 5 Linked Lists.
CS2006- Data Structures I Chapter 5 Linked Lists III.
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
CSCI387 Data Structure Fall Doubly Linked List Sep. 3, 2012 Sung Hee Park Computer Science Virginia State University.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Data Structure & Algorithms
1 CS 132 Spring 2008 Chapter 5 Linked Lists p
1 CMPT 117 Linked Lists (singly linked). 2 Problems with arrays  When an element is deleted from or inserted into an array, the rest of the array has.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
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.
Programming Circular Linked List.
C++ Programming:. Program Design Including
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Review Deleting an Element from a Linked List Deletion involves:
Doubly Linked List Review - We are writing this code
UNIT-3 LINKED LIST.
Linked lists.
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.
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 17: Linked Lists.
LINKED LISTS.
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
CS148 Introduction to Programming II
Linked lists.
Linked Lists.
Presentation transcript:

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 list and may be declared as shown. struct dblNode { int info; dblNode* prev; dblNode * next; }; dblNode* start; In this example, note that prev of the first node is set to NULL.

1.Consider doubly linked lists. a. What are the advantages that this structure offers? b. What are the disadvantages? c. Compare doubly linked lists with singly linked lists. When would you choose to use one rather then the other? 2.Write a search function for a doubly linked list. 3. Write a fragment of code to delete the node containing 190 from the doubly linked list shown above. How would the code change if you were asked to delete the node containing 90 or 290 instead?

Circularly Linked Lists

Exercises Circular Linked Lists Directions: Use the type declarations at the right as you write each of the following functions. Each function should contain pre- and post- conditions and should work for empty lists, lists containing only one node, and lists containing many nodes struct node { int info; node* next; node(int D, node *N) : info(D),next(N) { } }; node* list; 1.Given a singly-linked linear list, write a function to convert it to a circular list. 2.Write a function to print out the information stored in a circular list. 3.Write a function to count the nodes in a circular list. 4.Given two circular lists A and B, write an O(1) function to join them into one circular list A, leaving the other list B empty.

Linked List Variants

Data structure struct dnode{ int Data; struct dnode *right,*left;}; typedef struct dnode *NodePointer; void main() { NodePointer Head= NULL; } void InsertElement (NodePointer &Head,int number) { NodePointer NewNode; NewNode=(NodePointer)malloc(sizeof(struct dnode)); NewNode->Data=number; NodePointer here=Head; If (Head != NULL){go through right link of ‘here’ and add NewNode at the end. Connect the last node(‘here’) to the left link of NewNode. Right Link of NewNode will be NULL } If (Head==NULL){ Make NewNode as Head. Both ‘right’ and ‘left’ link of Head will be NULL } }

Try SORT a double linked list: Each node contains 1)Data 2) total no. of occurrence 3) Right link & 4)left link.  Insert each new element to the left of ‘Head’ if its data is less than Head and to right if its data is higher than ‘head’. If equal, increase ‘total no. of occurrence's count.

Linked List Variants

Sparse Matrix