Advanced Linked lists Doubly Linked and Circular Lists

Slides:



Advertisements
Similar presentations
Data Structures Using C++
Advertisements

Chapter 17 Linked List Saurav Karmakar Spring 2007.
Review Learn about linked lists
Variations on Linked Lists Ellen Walker CPSC 201 Data Structures Hiram College.
Computer Science 112 Fundamentals of Programming II Lists.
COMPSCI 105 S Principles of Computer Science Linked Lists 2.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
COMPSCI 105 S Principles of Computer Science Linked Lists 1.
Chapter 3: Arrays, Linked Lists, and Recursion
Variations of Linked Lists CS 308 – Data Structures.
Chapter 17 Linked List.
1 CSC 211 Data Structures Lecture 21 Dr. Iftikhar Azim Niaz 1.
Last meeting..Doubly Linked List  InsertToFront  InsertToEnd  Search  DeleteNode.
Data Structures Using Java1 Chapter 4 Linked Lists.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 18 Linked Lists, Stacks, Queues, and Priority Queues.
COMPSCI 105 SS 2015 Principles of Computer Science Linked Lists 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 11 – Data Structures.
Data Structures Using C++1 Chapter 5 Linked Lists.
CS2006- Data Structures I Chapter 5 Linked Lists III.
Linked Lists Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 17 © 2002 Addison Wesley.
Chapter 5 Linked Lists. © 2004 Pearson Addison-Wesley. All rights reserved 5 A-2 Preliminaries Options for implementing an ADT –Array Has a fixed size.
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
Tirgul 10. What We Will See Today:  Linked lists  Graphs  Trees  Iterators and Generators.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
© 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.
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.
Chapter 16: Linked Lists.
Fundamentals of Programming II Linked Lists
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Data structures and algorithms
Review Deleting an Element from a Linked List Deletion involves:
Lecture - 6 On Data Structures
COP3530- Data Structures Advanced Lists
UNIT-3 LINKED LIST.
Linked-list.
Linked List Variations
Chapter 4 Linked Lists
Revised based on textbook author’s notes.
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)
Chapter 18: Linked Lists.
Doubly linked lists Idea: same as singly linked list, but each node also points to the previous: Can optionally also have a pointer to the tail, so we.
ليست هاي پيوندي.
Linear Data Structures Chapter 3
Node Applications in Abstract Data Types
Chapter 17: Linked Lists.
LINKED LISTS.
LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)
Revised based on textbook author’s notes.
Linked Lists Chapter 5 (continued)
Chapter 9 Linked Lists.
CMPT 225 Lecture 5 – linked list.
Presentation transcript:

Advanced Linked lists Doubly Linked and Circular Lists Revised based on textbook author’s notes.

Doubly linked lists A linked list in which each node contains a data component(s) and two links: one pointing the next node and one pointing to the preceding node.

In Python’s term … The node storage class is similar to that of a singly linked list. class DListNode : def __init__( self, data ): self.data = data self.next = None self.prev = None

Doubly Linked: Insert (1) Insert in the middle before a given node.

Doubly Linked: Insert (1) Insert in the middle before a given node. node.next = cur node.prev = cur.prev node.prev.next = node cur.prev = node

Doubly Linked: Insert (2) Insert at the front.

Doubly Linked: Insert (2) Insert at the front. node.next = self.head self.head.prev = node self.head = node

Doubly Linked: Insert (3) Insert at the end.

Doubly Linked: Insert (3) Insert at the end. node.next = self.head self.head.prev = node self.head = node

Exercise How to find a node with a particular value? How to remove a node with a particular value in a doubly linked list? How to insert node into a sorted doubly linked list?

Circular Linked List Another variation of the linked list in which the nodes form a continuous circle. Allows for a complete traversal from any initial node. Used with round-robin type applications. The external reference can point to any node in the list. Common to reference “end” of the list.

Circular Linked List A circular linked list can also be doubly linked.

Circular Linked: Traverse Traverse forward following the next link

Circular Linked: Traverse Traverse backward following the prev link

Circular Linked: Inserting Adding nodes is very similar to that of the sorted singly linked list. Sorted list – new node is placed in proper position. Can be divided into four cases.

Circular Linked: Inserting (1) Insert into an empty list. ... if listRef is None : listRef = newNode newNode.next = newNode

Circular Linked: Inserting (2) Insert at the “front” (one node past listRef) ... if value < listRef.next.data : newNode.next = listRef.next listRef.next = newNode

Circular Linked: Inserting (3) Insert at the “end” (adjust listRef) ... if value > listRef.next.data : newNode.next = listRef.next listRef.next = newNode listRef = newNode

Circular Linked: Inserting (4) Insert in the middle.

Circular Linked: Inserting newnode = ListNode( value ) if listRef is None : # empty list listRef = newNode newNode.next = newNode elif value < listRef.next.data : # insert in front newNode.next = listRef.next listRef.next = newNode elif value > listRef.data : # insert in back else : # insert in the middle # Position the two pointers. predNode= None curNode = listRef done = listRef is None while not done : predNode = curNode predNode = curNode.next done = curNode is listRef or curNode.data > target # Adjust links to insert the node. newNode.next = curNode predNode.next = newNode Chapter 9: Advanced Linked Lists –