Lecture 20 Linked Lists Richard Gesick.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Linear Lists – Linked List Representation
Data Structures: A Pseudocode Approach with C
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Understand arrays and their usefulness. Understand records and the difference between.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Introduction to Data Structures Systems Programming.
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.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Linked List by Chapter 5 Linked List by
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
List Interface and Linked List Mrs. Furman March 25, 2010.
Introduction Dynamic Data Structures Grow and shrink at execution time Linked lists are dynamic structures where data items are “linked up in a chain”
 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.
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:
Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
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.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
Advanced Programming 7/10/20161 Ananda Gunawardena.
Linked Lists Source: presentation based on notes written by R.Kay, A. Hill and C.Noble ● Lists in general ● Lists indexed using pointer arrays ● Singly.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Lecture 6 of Computer Science II
COSC160: Data Structures Linked Lists
Chapter 4 Linked Structures.
Week 4 - Monday CS221.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Dynamic Allocation Review Structure and list processing
5.13 Recursion Recursive functions Functions that call themselves
Lectures linked lists Chapter 6 of textbook
12 C Data Structures.
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
Review Deleting an Element from a Linked List Deletion involves:
12 C Data Structures.
Chapter 22 Custom Generic Data Structures
John Hurley Cal State LA
Introduction to Data Structures
Linked Lists with Tail Pointers
CSCI 3333 Data Structures Linked Lists.
LINKED LISTS CSCD Linked Lists.
Topic 11 Linked Lists -Joel Spolsky
Object Oriented Programming COP3330 / CGS5409
Practice Test – Linked Lists
Arrays and Linked Lists
Linked Lists.
Introduction to Data Structures
Chapter 17: Linked Lists Starting Out with C++ Early Objects
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Linked Lists with Tail Pointers
CS2013 Lecture 4 John Hurley Cal State LA.
Review & Lab assignments
Chapter 17: Linked Lists.
Lecture 14 Linked Lists CSE /26/2018.
Lecture 15 Doubly Linked Lists CSE /26/2018.
List Iterator Implementation
BY PROF. IRSHAD AHMAD LONE.
Topic 11 Linked Lists -Joel Spolsky
CMPT 225 Lecture 5 – linked list.
Presentation transcript:

Lecture 20 Linked Lists Richard Gesick

Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection (i.e., a sequence) of nodes, connected by reference links (“chained together”). It can be singly or doubly linked A linked list is appropriate when the number of data elements is unpredictable. Linked lists become full only when the system has insufficient memory.

Nodes A self-referential class contains a member that refers to an object of the same class type. In the class declaration Next references an object of type Node, an object of the same type being declared. Next is referred to as a link. class Node { public string data; public Node next ; }

Common tasks include: Inserting to the front Inserting to the end Inserting in between the front/end Deleting Searching Sorting Each of these tasks takes different amounts of time depending upon how the linked list is implemented

A Singly Linked List A backslash indicates a null link. Not setting the link in the last node of a list to null is a logic error.

C# doubly linked list The linked list class in C# is a generic and doubly linked which means that we have direct access to the front and the end of the linked list. LinkedList<string> LL1 = new LinkedList<string>(); LL1.AddFirst("a"); LL1.AddLast("c");

doubly linked lists  data data data data data  head tail

Nodes The nodes of the linked list are called LinkedListNodes and are also generic. LinkedListNode<string> myNode = LL1.First; First and Last are properties of the LinkedList class that allow direct access to the first and last nodes respectively.

Traversing by Node using Iteration public static void PrintList (LinkedList<string> L) { LinkedListNode<string> myNode = L.First; while (myNode != null) { Console.Write(myNode.Value + " "); myNode = myNode.Next; } Console.WriteLine();

Traversing with a foreach loop public static void PrintList1(LinkedList<string> L) { foreach (string s in L) Console.Write(s + " "); Console.WriteLine(); }