Data Structures and Database Applications Linked Lists

Slides:



Advertisements
Similar presentations
Linked Lists Linked Lists Representation Traversing a Linked List
Advertisements

Lists1 © 2010 Goodrich, Tamassia. Position ADT The Position ADT models the notion of place within a data structure where a single object is stored It.
CHP-5 LinkedList.
Chapter 9: Data Structures I
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
Chapter 6 Linked Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Topic 11 Linked Lists -Joel Spolsky
Chapter 12: Data Structures
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
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.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Reference: Vinu V Das, Principles of Data Structures using C and C++
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Arrays and Linked Lists "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101,
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 18 Linked Lists, Stacks, Queues, and Priority Queues.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
ELC 310 Day 24. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Agenda Questions? Problem set 5 Parts A & B Corrected  Good results  2 A’s, 1.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
List Interface and Linked List Mrs. Furman March 25, 2010.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
 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:
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
Java Software Solutions Foundations of Program Design Seventh Edition
Linked List, Stacks Queues
Chapter 4 Linked Structures.
Data Structure By Amee Trivedi.
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
Double-Ended Queues Chapter 5.
Ch7. List and Iterator ADTs
Program based on queue & their operations for an application
CS2006- Data Structures I Chapter 5 Linked Lists I.
Linked List Stacks, Linked List Queues, Dequeues
Sequences and Iterators
Doubly Linked List Review - We are writing this code
Chapter 12: Data Structures
Linked-list.
Data Structures and Database Applications Abstract Data Types
Chapter 12 Collections.
Data Structures and Database Applications Queues in C#
Topic 11 Linked Lists -Joel Spolsky
Array Lists, Node Lists & Sequences
Database Linked List Representation
Ch7. List and Iterator ADTs
Data Structures and Database Applications Stacks in C#
Chapter 13 Collections.
Lecture 20 Linked Lists Richard Gesick.
Arrays and Collections
List Implementations Chapter 9.
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.
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Problem Understanding
Chapter 12 Collections.
The Generic LinkedList<> Collection class
Header and Trailer Sentinels
Lecture 15 Doubly Linked Lists CSE /26/2018.
Linked Lists.
Chapter 9 Linked Lists.
Topic 11 Linked Lists -Joel Spolsky
Presentation transcript:

Data Structures and Database Applications Linked Lists

LinkedList System.Collections.Generic.LinkedList Automatic resizing and homogeneous list Represents a doubly linked list of nodes

Object References Recall that an object reference is a variable that stores the address of an object A reference also can be called a pointer References often are depicted graphically: student John Smith 40725 3.58

References as Links Object references can be used to create links between objects Suppose a class contains a reference to another object of the same class: class Node { Object info; Node next; }

References as Links References can be used to create a variety of linked structures, such as a linked list:

Using Intermediate Nodes The objects being stored should not be concerned with the details of the data structure in which they may be stored For example, a list of students created with a Student class should not have to store a link to the next Student object in the previous Student object Instead, a separate node class is used in the LinkedList class which serves two functions: It has a reference to the data object (e.g the Student object) It has a link to the next (and possibly previous) nodes in the list The internal representation becomes a linked list of nodes

Inserting a Node Internally, a node is inserted into a linked list with a few reference changes:

Deleting a Node Likewise, a node is removed from a linked list by changing the next pointer of the preceding node:

Other Dynamic Representations When a linked list structure has both next and previous references, it is a doubly linked list: class Node { Object info; Node next; Node prev; }

LinkedList Example: LinkedList<string> sentence = new LinkedList<string>(); // instantiates ls object sentence.AddFirst("fox"); // add "fox" as first item sentence.AddLast("jumped"); // add “jumped" as last item sentence.AddLast("dog"); // add “dog" as new last item sentence.AddBefore(sentence.Last, "the"); // add “the” before “dog” LinkedListNode<string> current = sentence.First; while (current.Next != null) // loop through all values { Console.Write(current.Value + " "); current = current.Next; } // prints: fox jumped the dog Console.WriteLine();

LinkedList Example (continued): sentence.AddAfter(sentence.First.Next, "over"); // add "over" after "jumped" sentence.AddFirst("the"); // add "the" as first word LinkedListNode<string> current = sentence.First; while (current.Next != null) { Console.Write(current.Value + " "); current = current.Next; } // now prints: the fox jumped over the dog Console.WriteLine(); Console.ReadLine();

Other Dynamic Representations Internally, a linked list can also use a separate header node, which can store the amount of nodes (count) and references to both the front and rear of the list:

Common LinkedList Methods AddAfter() AddBefore() AddFirst() AddLast() Remove() RemoveFirst() RemoveLast() Clear() Contains() Find() FindLast()