Linked Lists Chapter 17. 2 Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.

Slides:



Advertisements
Similar presentations
Chapter 17 Linked Lists.
Advertisements

Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
CSEB324 Data Structures & Algorithms
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Linked Lists
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.
COMP103 - Linked Lists (Part A)1 Chapter 17 Truly dynamic memory management.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
1 CSC 211 Data Structures Lecture 10 Dr. Iftikhar Azim Niaz 1.
C++ is Fun – Part 14 at Turbine/Warner Bros.! Russell Hanson.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Reference: Vinu V Das, Principles of Data Structures using C and C++
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
1 Data Structures CSCI 132, Spring 2014 Lecture 20 Linked Lists.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Linked Lists. Array List Issues Painful insert/remove at start/middle.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 CSC 211 Data Structures Lecture 11 Dr. Iftikhar Azim Niaz 1.
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:
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.
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Data Structure & Algorithms
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
Linked Lists and Generics Written by J.J. Shepherd.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
1 CSE 2341 Object Oriented Programming with C++ Note Set #18.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming:. Program Design Including
Chapter 12 – Data Structures
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
List ADT & Linked Lists.
Linked lists.
Linked Lists.
CSCI 3333 Data Structures Linked Lists.
Chapter 20: Binary Trees.
Chapter 21: Binary Trees.
Chapter 18: Linked Lists.
Chapter 17: Linked Lists Starting Out with C++ Early Objects
Chapter 17: Linked Lists.
Lecture 14 Linked Lists CSE /26/2018.
CS148 Introduction to Programming II
Linked lists.
Linked Lists.
Linked List Insert After
Linked Lists.
Presentation transcript:

Linked Lists Chapter 17

2 Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures NULL list head

3 Introduction To The Linked List ADT Data structures can be added to or removed from the linked list during execution NULL list head newNode

4 Linked Lists Linked lists can grow and shrink as needed, unlike arrays, which have a fixed size Linked lists can insert a node between other nodes easily NULL list head

5 Node Organization A node contains: –data: one or more data fields – may be organized as structure, object, etc. –a pointer that can point to another node data pointer

6 Linked List Organization Linked list contains 0 or more nodes: Has a list head to point to first node Last node points to NULL NULL list head

7 Empty List If a list currently contains 0 nodes, it is the empty list In this case the list head points to NULL NULL list head

8 Declaring A Node Declare a node: struct ListNode { int data; ListNode *next; }; No memory is allocated at this time

9 Defining A Linked List Define a pointer for the head of the list: ListNode *head = NULL; Head pointer initialized to NULL to indicate an empty list NULL head

10 Linked List Operations Basic operations: –append a node to the end of the list –insert a node within the list –traverse the linked list –delete a node –delete/destroy the list

11 Create A New Node Allocate memory for the new node: newNode = new ListNode; Initialize the contents of the node: newNode->value = num; Set the pointer field to NULL : newNode->next = NULL; NULL newNode 23 newNode 23

12 Appending A Node Add a node to the end of the list Basic process: –Create the new node (as already described) –Add node to the end of the list: If list is empty, set head pointer to this node Else, –traverse the list to the end –set pointer of last node to point to new node

13 Appending A Node NULL list head newNode 23 NULL nodePtr New node created, end of list located

14 Appending A Node list head newNode 23 NULL nodePtr New node added to end of list

15 Inserting A Node Into A Linked List Used to maintain a linked list in order Requires two pointers to traverse the list: –pointer to locate the node with data value greater than that of node to be inserted –pointer to 'trail behind' one node, to point to node before point of insertion New node is inserted between the nodes pointed at by these pointers

16 Inserting A Node Into A Linked List NULL list head newNode 17 NULL nodePtrpreviousNode New node created, correct position located

17 Inserting A Node Into A Linked List NULL list head newNode 17 nodePtrpreviousNode New node inserted in order in the linked list

18 Traversing A Linked List Visit each node in a linked list: display contents, validate data, etc. Basic process: –set a pointer to the contents of the head pointer –while pointer is not NULL process data go to the next node by setting the pointer to the pointer field of the current node in the list –end while

19 Traversing A Linked List NULL list head nodePtr nodePtr points to the node containing 5, then the node containing 13, then the node containing 19, then points to NULL, and the list traversal stops

20 Deleting A Node Used to remove a node from a linked list If list uses dynamic memory, then delete node from memory Requires two pointers: one to locate the node to be deleted, one to point to the node before the node to be deleted

21 Deleting A Node NULL list head nodePtrpreviousNode Locating the node containing 13

22 Deleting A Node NULL list head nodePtrpreviousNode Adjusting pointer around the node to be deleted

23 Deleting A Node NULL list head 519 nodePtrpreviousNode Linked list after deleting the node containing 13