Double Linked List Operations Dr. David Tsai 2010/4/12.

Slides:



Advertisements
Similar presentations
Chapter 3: Linked List Tutor: Angie Hui
Advertisements

Linked List Alternate approach to maintaining an array of elements Rather than allocating one large group of elements, allocate elements as needed Q: how.
Chapter 5 introduces the often- used data structure of linked lists. This presentation shows how to implement the most common operations on linked lists.
Linked Lists Mohammed Almashat CS /03/2006.
Page 11 Solutions to Practice Problems Using a Linked List From Previous Days Notes Create C functions to solve the following problems with linked lists.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Stacks, Queues, and Linked Lists
Linked Lists.
CSCE 3110 Data Structures & Algorithm Analysis
Linear Lists – Linked List Representation
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
CSEB324 Data Structures & Algorithms
Fall 2005 Data Structure Linked List – Single Linked List.
CS Data Structures Chapter 4 Lists. Chain (1/3) Chain: Chain: A singly linked list in which the last node has a null link A singly linked list in.
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
CSCE 3110 Data Structures & Algorithm Analysis
LIST PROCESSING.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Linked List Variations
CSCI2100B Linked List Jeffrey
Dynamic memory allocation
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
§2 Binary Trees Note: In a tree, the order of children does not matter. But in a binary tree, left child and right child are different. A B A B andare.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Doubly-linked list library.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
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.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
指標 Pointers.
C Intro.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
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.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
Growing Arrays in C By: Victoria Tielebein CS 265- Spring 2011.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Introduction to C Programming CE Lecture 20 Insertion and Deletion with Linear Linked Lists.
CCSB364 Data Structures & Algorithms Pointer & Linked List.
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.
Insertion into a B+ Tree Null Tree Ptr Data Pointer * Tree Node Ptr After Adding 8 and then 5… 85 Insert 1 : causes overflow – add a new level * 5 * 158.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
CGS 3460 Pointer n To hold the location of another variable n Declaration: la type and a name with an asterisk lE.g. int *ptr; n Assigning a value lptr.
Introduction to Data Structures Systems Programming.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
A Doubly Linked List prevnextdata There’s the need to access a list in reverse order header dnode.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
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.
Linked Lists and Generics Written by J.J. Shepherd.
UNIT-II Topics to be covered Singly linked list Circular linked list
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
UNIT – I Linked Lists.
Linked List.
Data Structures 7th Week
Linked List Insert as a first node Insert as a last node
Review & Lab assignments
CS148 Introduction to Programming II
Linked Lists.
Presentation transcript:

Double Linked List Operations Dr. David Tsai 2010/4/12

void createDList (int len, int*array) { int i; DList newnode, before; first = (DList) malloc (sizeof (DNode) ); first->data = array[0]; first->previous = first->next = NULL; before = first /*now = first; */ for (i = 1; i < len; i++) { newnode = (DList) malloc (sizeof(Dnode) ); newnode->data = array[i]; newnode->next = NULL; newnode->previous = before; before->next = newnode; before = newnode; } C /

60 first NULL before 50 newnode NULL 40 NULL

void printDList () { DList now = first; while (now! = NULL) { back = now; printf ( %d, now->data); now = now->next; } printf ( \n ); now = back->previous; while (now! = NULL) { back = now; printf ( %d, now->data); now = now->previous; } printf ( \n ); }

now 60 first NULL 50 NULL 40 back

void deleteDNode (DList ptr) { if (ptr->previous == NULL) { first = first->next; first->previous = NULL; } else { if (ptr->next == NULL) { ptr->previous->next = NULL; } else{ ptr->previous->next = ptr->next; ptr->next->previous = ptr->previous; } free (ptr); }

ptr 60 first NULL 50 NULL NULL To Delete First Node

ptr 60 first NULL 50 NULL To Delete Last Node NULL

ptr 60 first NULL 50 NULL To Delete a Middle Node

void insertDNode (DList ptr, int d) { DList newnode = (DList) malloc (sizeof (DNode) ) ; newnode->data = d; newnode->next = newnode->previous = NULL; if (first == NULL) { first = newnode; } if (ptr == NULL) { newnode->previous = NULL; newnode->next = first; first->previous = newnode; first = newnode; } else { if (ptr->next == NULL) { ptr->next = newnode; newnode->previous = ptr; newnode->next = NULL; } else { ptr->next->previous = newnode; newnode->next = ptr->next; newnode->previous = ptr; ptr->next = newnode; } } }

50 first = 40 newnode == = = 60 ptr = = To Create a Double Linked List To Insert a New Node at Front of the First Node To Insert a New Node at End of the Last Node

50 first 40 newnode = = = 60 ptr = 55 To Insert a New Node into the Middle of the List