Chapter 17: Linked Lists.

Slides:



Advertisements
Similar presentations
Chapter 17 Linked Lists.
Advertisements

Linked Lists.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth 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.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
2 Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
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.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
2/21/20161 List Operations Advanced Programming Ananda Gunawardena.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
CS162 - Topic #7 Lecture: Dynamic Data Structures –Review of pointers and the new operator –Introduction to Linked Lists –Begin walking thru examples of.
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 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
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.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Standard Template Library
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Linked List ADT used to store information in a list
Unit – I Lists.
C++ Programming:. Program Design Including
Chapter 4 Linked Structures.
Pointers and Linked Lists
Chapter 12 – Data Structures
Pointers and Linked Lists
5.13 Recursion Recursive functions Functions that call themselves
CSCI-255 LinkedList.
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
Linked Lists.
UNIT-3 LINKED LIST.
Chapter 4 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.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
CSCI 3333 Data Structures Linked Lists.
Programmazione I a.a. 2017/2018.
LINKED LISTS CSCD Linked Lists.
Object Oriented Programming COP3330 / CGS5409
Arrays and Linked Lists
Chapter 18: Linked Lists.
Chapter 17: Linked Lists Starting Out with C++ Early Objects
Doubly Linked List Implementation
Recursive Linked List Operations
Linked Lists Chapter 4.
Problem Understanding
Evaluation of List Implementations
Linked List Intro CSCE 121.
Doubly Linked List Implementation
Chapter 9 Linked Lists.
LINEAR DATA STRUCTURES
Presentation transcript:

Chapter 17: Linked Lists

Introduction to Linked List 17.1 Introduction to Linked List

Introduction to Linked List A linked list is a series of connected nodes, where each node is a data structure. A linked list can grow or shrink in size as the program runs Nodes are dynamically allocated

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 pointer data

Declaring a Node Declare a node: struct ListNode { };

Declaring a Node Declare a node: struct ListNode { int data; ListNode *next; }; The pointer can hold the address of any object that is a ListNode structure. Self-referential data structure

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

NULL NULL is a named constant, defined in the iostream file, that stands for address 0. The address 0 is considered an unusable address. Most computers store special operating system data structures in the lower areas of memory.

Empty List If a list currently contains 0 nodes, it is the empty list

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

Linked List Operations 17.2 Linked List Operations

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

Advantage of Linked Lists Advantage of linked lists over arrays It is faster to insert a node into a linked list or delete one from the list

Linked Lists vs. Arrays Linked lists can insert a node between other nodes easily NULL list head

Variations of the Linked List Other linked list organizations: doubly-linked list: each node contains two pointers: one to the next node in the list, one to the previous node in the list NULL list head 5 13 19

Variations of the Linked List Other linked list organizations: circular linked list: the last node in the list points back to the first node in the list, not to NULL list head 5 13 19

The STL list Container Template for a doubly linked list Member functions for adding elements to the list: insert, push_back, push_front removing elements from the list: erase, pop_back, pop_front