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
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

Chapter 17 Linked Lists.
Linked Lists.
Linear Lists – Linked List Representation
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
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.
List Representation - Chain Fall 2010 CSE, POSTECH.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Understand arrays and their usefulness. Understand records and the difference between.
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.
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.
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.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
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 Lists – Linked List Representation CSE, POSTECH.
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.
Linear List Linked Representation. Linked Representation list elements are stored, in memory, in an arbitrary order explicit information (called a link)
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
1 Writing a Good Program 8. Elementary Data Structure.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
(c) University of Washington16-1 CSC 143 Java Linked Lists Reading: Ch. 20.
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
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.
SNU IDB Lab. Ch6. Linear Lists – Linked Representation © copyright 2006 SNU IDB Lab.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
CS-2852 Data Structures LECTURE 5 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
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:
CSCS-200 Data Structure and Algorithms Lecture
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.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
  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.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Reminder: Course Policy
C++ Programming:. Program Design Including
Review Deleting an Element from a Linked List Deletion involves:
Data Structure Dr. Mohamed Khafagy.
UNIT-3 LINKED LIST.
Linked lists.
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
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 List Yumei Huo Department of Computer Science
The Class chain.
Simulated Pointers.
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.
Simulated Pointers.
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
Chapter 11 Data Structures.
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.
The Class chain.
Data Structures & Algorithms
Linked lists.
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. (^denotes computer memory)

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

Operations on a linked list Possible operations –Get an element –Remove an element –Insert an element We first discuss the codes for represent an node, then discuss the operations.

Node and Chain Representation (See Program P186) template class ChainNode { private: T data; ChainNode *link; // constructors come here }; template class Chain {... private: ChainNode *first; } link data

Constructors Of ChainNode ChainNode() {} ? ? ? data link data ChainNode(const T& data) {this->data = data;} ChainNode(const T& data, chainNode * link) {this->data = data; this->link = link;}

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; delete deleteNode; 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; delete deleteNode; beforeNode abcde null first

Insert(0,’f’) abcde NULL first f newNode Step 1: get a node, set its data and link fields newNode = new ChainNode (theElement, first);

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

One-Step Insert(0,’f’) abcde NULL first f newNode first = new chainNode (‘f’, first);

Insert(3,’f’) first find node whose index is 2 abcde NULL first f newNode beforeNode c next create a node and set its data and link fields ChainNode * newNode = new ChainNode ( ‘f’, beforeNode  link); finally link beforeNode to newNode beforeNode  link = newNode;

Two-Step Insert(3,’f’) beforeNode = first  link  link; beforeNode  link = new ChainNode (‘f’, beforeNode  link); abcde NULL first f newNode beforeNode c

In Class Exercise Write down the pseudo code for the function insert(int n, char c)