CSCI387 Data Structure- 2012 Fall Doubly Linked List Sep. 3, 2012 Sung Hee Park Computer Science Virginia State University.

Slides:



Advertisements
Similar presentations
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

Stacks, Queues, and Linked Lists
DATA STRUCTURES USING C++ Chapter 5
Double Linked List Operations Dr. David Tsai 2010/4/12.
Linked List Variations
Data Structure Lecture-5
Doubly-linked list library.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
3 May Linked Lists CSE 2011 Winter Linked Lists2 Singly Linked Lists (3.2) A singly linked list is a concrete data structure consisting of.
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.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 11 Implementing.
CS 206 Introduction to Computer Science II 02 / 06 / 2009 Instructor: Michael Eckmann.
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.
Class 3: Linked Lists. cis 335 Fall 2001 Barry Cohen What is a linked list? n A linked list is an ordered series of ‘nodes’ n Each node contains some.
CS 206 Introduction to Computer Science II 09 / 15 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 09 / 2009 Instructor: Michael Eckmann.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
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.
ADSA: Linked Lists/ Advanced Data Structures and Algorithms Objective – –implement and use linked lists Semester 2, Linked.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
A Doubly Linked List prevnextdata There’s the need to access a list in reverse order header dnode.
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.
12/18/2015ITK 2751 CollectionList A bstractSequentialList Vector Stack LinkedList {interface} AbstractList {abstract} ArrayList Java Provides a List interface.
© 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.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS2006- Data Structures I Chapter 5 Linked Lists III.
1 Objectives of these slides: to describe linked lists in C 6 – Lists.
COMPSCI 105 SS 2015 Principles of Computer Science
COMP x1 Computing 2 C Outside the Style Guide, Linked Lists and Function Pointers 1.
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
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.
1 Circular, Doubly-Linked Lists Node Composition List Class Pushing and Popping Values Insert and Erase at Arbitrary Locations List Implementation.
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
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.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
C++ Programming:. Program Design Including
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
UNIT – I Linked Lists.
Review Deleting an Element from a Linked List Deletion involves:
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
UNIT-3 LINKED LIST.
Linked List Variations
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Data Structures and Algorithms IT12112
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Circularly Linked Lists
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 17: Linked Lists.
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
CS148 Introduction to Programming II
Linked Lists Chapter 5 (continued)
Presentation transcript:

CSCI387 Data Structure Fall Doubly Linked List Sep. 3, 2012 Sung Hee Park Computer Science Virginia State University

Assignment 03- Linked List Programming -DataStructure/assignments/assignment03- LinkedList/assignment03-LinkedList.pdf -DataStructure/assignments/assignment03- LinkedList/assignment03-LinkedList.pdf Due: 9/6/ :55pm

What is the output? a.cout item b.cout item c.cout next->item d.cout next->next->item Item next list AB

What is the value of the following relational expressions? a.list->item >= 18 b.list->next->next== A c.A->next->item == 55 d.B->next == NULL e.list->item == 18 True False list AB

list AB Mark each of the following statements as valid or invalid? If a statement is invalid, explain why. a.A = B; b.list->next = A->next; c.list->next->item = 45; d.*list =B; e.*A = *B; f.B = A ->next ->item; g.A ->item = B->item; h.list = B->next->next; i.B = B ->next->next -> next; a. Valid b. Valid c. Valid d. Invalid; B is a pointer whereas *List is a struct. e. Valid f. Invalid; B is a pointer whereas A->next->item is an int. g. Valid h. Valid i. Invalid, B->next->next is null, which does not have a ‘next’ pointer.

Write C++ statements to do the following: a.Make A point to the node containing item 23. b.Make list point to the node containing item 16. c.Make B point to the last node in the list. d.Make list point to any empty list. e.Set the value of the node containing 55 to 35. a.A = List; b.List = A->next; c.B = B->next; d.List = NULL; e.A->next->next->item = 35; list AB

Doubly Linked List Conceptual picture list head tail

Doubly Linked List - Node typedef struct dNode { int data;// will store information node *next; // the reference to the next node node *prev; // the reference to the previous node };

Insert a new node at position curr preNode = curr->prev; newNode->prev = prevNode; // statement (1) prevNode->next = newNode; // statement (2) curr->prev = newNode; // statement (3) New->next = curr;// statement (4) (1)(2) (3) (4) newNode prevNode = curr->prevcurr

Delete node curr preNode = curr->prev; succNode = curr->next; preNode->next = succNode;// statement (1) succNode->prev = prevNode;// statement (2) newNode prevNode = curr->prevcurrsuccNode = curr->next (1) (2)

Circular Doubly Linked Lists Conceptual picture list head

Circular Doubly Linked Lists Example list 2 head 349 last=head->prev;first=head->next;

Declaring a Doubly Linked List Empty Doubly Linked List next prev head null head->next = head; head->prev = head; Empty Singly Linked List head = null;

In Class Activity – Doubly Linked List 1) Implement addBefore(dNode curr, int item) in C++ dNode addBefore(dNode curr, int item) { // }

(1)(2) (3) (4) newNode prevNode = curr->prevcurr

In Class Activity – Doubly Linked List 2) Implement remove(dNode curr, int item) in C++ dNode addBefore(dNode curr) { // }

newNode prevNode = curr->prevcurrsuccNode = curr->next (1) (2)

In Class Activity – Circular Doubly Linked List Depict each statement in a circular doubly linked list with a starting pointer head. – addBefore(head->next, a); – remove(head->next) – addBefore(head, a); – remove(head->prev);