Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Stacks, Queues, and Linked Lists
Linked Lists.
CSCE 3110 Data Structures & Algorithm Analysis
Linked Lists Linked Lists Representation Traversing a Linked List
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Foundation of Computing Systems Lecture 2 Linked Lists.
1 Linked Lists Gordon College Prof. Brinton. 2 Linked List Basics Why use? 1.Efficient insertion or deletion into middle of list. (Arrays are not efficient.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
CS102--Object Oriented Programming Lecture 17: – Linked Lists Copyright © 2008 Xiaoyan Li.
Linked Lists. Preliminaries Options for implementing an ADT List Array Has a fixed size Data must be shifted during insertions and deletions Dynamic array.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Data Structures Using C++ 2E
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection.
Linked List (Part II). Introduction  Definition of equivalence relation: A relation ≡ over a set S, is said to be an equivalence relation over S iff.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists.
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.
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,
Ceng-112 Data Structures ISerap ATAY, Ph. D. 1 Chapter 3 – Part 2 Linear Lists.
Linked lists. Data structures to store a collection of items Data structures to store a collection of items are commonly used Typical operations on such.
2/21/20161 List Operations Advanced Programming Ananda Gunawardena.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Data Structures AZHAR MAQSOOD NUST Institute of Information Technology (NIIT) Lecture 6: Linked Lists Linked List Basics.
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 Data Structures and Algorithms Outline This topic will describe: –The concrete data structures that can be used to store information –The basic forms.
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.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
UNIT-II Topics to be covered Singly linked list Circular linked list
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Data Structure By Amee Trivedi.
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Lists CS 3358.
UNIT-3 LINKED LIST.
CSCE 210 Data Structures and Algorithms
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Chapter 16-2 Linked Structures
Object Oriented Programming COP3330 / CGS5409
Arrays and Linked Lists
Chapter 18: Linked Lists.
Lecture 20 Linked Lists Richard Gesick.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Linked Lists Chapter 4.
Problem Understanding
Chapter 17: Linked Lists.
Lecture 14 Linked Lists CSE /26/2018.
Linked Lists.
C Programming Lecture-8 Pointers and Memory Management
Data Structures & Algorithms
Programming II (CS300) Chapter 07: Linked Lists
Linked Lists.
LINEAR DATA STRUCTURES
Presentation transcript:

Lecture 16 Linked Lists

In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes

Fundamentals of Linked Lists A dynamic data structure Head pointer indicates the beginning of the list List traversal starts from the head NULL pointer indicates the end of the list List traversal ends at NULL or when the goal is reached Head 10 ff 20 aa 32 f NULL

Fundamentals of Linked Lists Three logically distinct forms of linked lists – Empty List – List with only one node – List with more than one node Head NULL Head 10 ff NULL Head NULL

Types of Linked Lists Single linked list This is the most basic type of linked list, with each node containing a single pointer, to the next node. Multi linked list More advanced than the single linked list, each node may be connected to many other nodes. Special case : Doubly linked lists Circular linked list With a circular linked list, the last node is connected to the first, to form a circle. Head NULL Head NULL Head

Examples Linked Lists Read a file and build a list of nodes in order. Insert a new node in order. Delete a node. Search for a target node (single linked list) Multi Linked List : The standard use of multi-linked lists is to organize a collection of elements in many different ways. For example, suppose my elements include the name of a person and his/her age. e.g. (FRED,19) (MARY,16) (JACK,21) (JILL,18). I might want to order these elements alphabetically and also order them by age. I would have two pointers - NEXT-alphabetically, NEXT-age - and the list header would have two pointers, one based on name, the other on age. Age pointer name pointer Fred 19Jack 21Jill 18Mary 16 NULL

Examples of Doubly Linked Lists Sparse Matrices - common use A sparse matrix is a matrix of numbers, in which almost all the entries are zero. These arise frequently in engineering applications. Typically only about N elements are non-zero. For example: We can represent this by having linked lists for each row and each column. Because each node is in exactly one row and one column it will appear in exactly two lists - one row list and one column. So it needs two pointers: Next-in-this-row and Next-in-this-column. In addition to storing the data in each node, it is normal to store the co- ordinates (i.e. the row and column the data is in in the matrix). Operations that set a value to zero cause a node to be deleted, and vice versa

Sparse Matrix Implementation

Doubly Linked List - An Example

Class Node class Node { public Node(); public Node(int x) ; public Node(int x, Node ptr) public Node getPtr(); public int getValue(); public void setPtr(Node ptr); public void setValue(int) ; private int value; private Node next; }; value next

Implementing node methods Constructors Node() { value = 0; next = NULL;} Node(int x) { value = x;} Node(int x, Node ptr) {value = x; next = ptr;} Accessors Node getPtr() { return next;} int getValue() { return value;} Mutators void setPtr(Node ptr) { next = ptr;} void setValue(int) { value = next;}

Graph Implementation - class Edge class Edge { int dest; double cost; Edge next; Edge(int d, double c, Edge link) {dest=d, cost=c, next=link} };