Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.

Slides:



Advertisements
Similar presentations
Linked Lists.
Advertisements

CSCE 3110 Data Structures & Algorithm Analysis
Linear Lists – Linked List Representation
Linked Lists Linked Lists Representation Traversing a Linked List
CSCI2100B Linked List Jeffrey
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Doubly-linked list library.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
List Representation - Chain Fall 2010 CSE, POSTECH.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
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.
Iterators & Chain Variants. Iterators  An iterator permits you to examine the elements of a data structure one at a time.  C++ iterators Input iterator.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
CS Data Structures Chapter 4 Lists.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
L.Chen1 Chapter 3 DATA REPRESENTATION(2) L.Chen A Chain Iterator Class A Chain Iterator Class ( 遍历器类 )  An iterator permits.
Iterators & Chain Variants. Iterators  An iterator permits you to examine the elements of a data structure one at a time.  C++ iterators Forward iterator.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Linear List Linked Representation. Linked Representation list elements are stored, in memory, in an arbitrary order explicit information (called a link)
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Data Structures Using Java1 Chapter 4 Linked Lists.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
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.
© 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.
The Class Chain. next (datatype ChainNode) element (datatype Object) Use ChainNode abcde null firstNode size = number of elements.
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,
1 PART 4 Linked Lists Singly Linked Lists Circular Lists Applications Doubly Linked Lists Generalized Lists.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
SNU IDB Lab. Ch6. Linear Lists – Linked Representation © copyright 2006 SNU IDB Lab.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
CS261 Data Structures Linked Lists - Introduction.
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 Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
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.
UNIT-II Topics to be covered Singly linked list Circular linked list
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Reminder: Course Policy
Review Deleting an Element from a Linked List Deletion involves:
Data Structure Dr. Mohamed Khafagy.
UNIT-3 LINKED LIST.
EEE2108: Programming for Engineers Chapter 4. Linked Lists
CSC172 Data Structures Linked Lists (C version)
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
The Class chain.
Programmazione I a.a. 2017/2018.
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Linked Representation
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Chapter 17: Linked Lists.
The Class chain.
The Class chain.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Presentation transcript:

Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next

Memory Layout abcdecaedb A linked representation uses an arbitrary layout. Layout of L = (a,b,c,d,e) using an array representation.

Linked Representation pointer (or link) in e is NULL caedb use a variable first to get to the first element a first

Normal Way To Draw A Linked List link or pointer field of node data field of node abcde NULL first

Chain A chain is a linked list in which each node represents one element. There is a link or pointer from one element to the next. The last node has a NULL (or 0) pointer. abcde NULL first

Node Representation typedef struct listNode *listPointer; typedef struct { char data; listPointer link; } listNode; link data

get(0) desiredNode = first; // gets you to first node return desiredNode  data; abcde NULL first

get(1) desiredNode = first  link; // gets you to second node return desiredNode  data; abcde NULL first

get(2) desiredNode = first  link  link; // gets you to third node return desiredNode  data; abcde NULL first

get(5) desiredNode = first  link  link  link  link  link; // desiredNode = NULL return desiredNode  data; // NULL.element abcde NULL first

Delete An Element delete(0) abcde NULL first deleteNode = first; first = first  link; free(deleteNode);

abde NULL first c delete(2) first get to node just before node to be removed c c beforeNode = first  link ; b beforeNode

delete(2) save pointer to node that will be deleted deleteNode = beforeNode  link; beforeNode abcde null first

delete(2) now change pointer in beforeNode beforeNode  link = beforeNode  link  link; free(deleteNode); beforeNode abcde null first

insert(0,’f’) abcde NULL first f newNode Step 1: get a node, set its data and link fields MALLOC( newNode, sizeof(*newNode)); newNode->data = ‘f’; newNode->link = NULL;

insert(0,’f’) abcde NULL first f newNode Step 2: update first first = newNode;

insert(3,’f’) first find node whose index is 2 abcde NULL first f newNode beforeNode c next create a new node and set its data and link fields finally link beforeNode to newNode

insert(3,’f’) beforeNode = first  link  link; MALLOC( newNode, sizeof(*newNode)); newNode->data = ‘f’; newNode->link = beforeNode->link; beforeNode  link = newNode; abcde NULL first f newNode beforeNode c

Chain With Header Node abcde NULL headerNode

Empty Chain With Header Node headerNode NULL

Circular List abcde firstNode

Doubly Linked List abcde NULL firstNode NULL lastNode

Doubly Linked Circular List abcde firstNode

Doubly Linked Circular List With Header Node abce headerNode d

Empty Doubly Linked Circular List With Header Node headerNode