The List ADT Sections 3.2, 3.3, 3.5 Introduction

Slides:



Advertisements
Similar presentations
1 Linked lists Sections 3.2, 3.3, 3.5 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors.
Advertisements

Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Lists: An internal look
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Lecture No.01 Data Structures Dr. Sohail Aslam
Data Structures Using C++ 2E
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
1 Joe Meehean.  Conceptual Picture N items chained together using pointers pointed to by head variable  Advantage allows list to grow indefinitely without.
Generic Positional Containers and Double-Ended Queues.
A Generic List Class and Linked Lists Andy Wang Data Structures, Algorithms, and Generic Programming.
A Doubly Linked List prevnextdata There’s the need to access a list in reverse order header dnode.
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.
The List ADT Reading: Sections 3.2, 3.3, 3.5.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Lecture 7.  There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library  Allows us.
1 Circular, Doubly-Linked Lists Node Composition List Class Pushing and Popping Values Insert and Erase at Arbitrary Locations List Implementation.
1 Generic Positional Containers and Double-Ended Queues.
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.
CS212: Object Oriented Analysis and Design
Chapter 16: Linked Lists.
C++ Programming:. Program Design Including
COSC160: Data Structures Linked Lists
The List ADT.
Cpt S 122 – Data Structures Abstract Data Types
Pointers and Linked Lists
Data Structure By Amee Trivedi.
Pointers and Linked Lists
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Big-O notation Linked lists
MIS 215 Module 1 – Unordered Lists
Doubly Linked List Review - We are writing this code
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Chapter 4 Linked Lists
Trees 4 The B-Tree Section 4.7
The Bag and Sequence Classes with Linked Lists
LINKED LISTS CSCD Linked Lists.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
CMSC 341 Lecture 5 Stacks, Queues
Chapter 16-2 Linked Structures
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Object Oriented Programming COP3330 / CGS5409
Generic Positional Containers and Double-Ended Queues
Chapter 18: Linked Lists.
Pointers and Linked Lists
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
CS212D: Data Structures Week 5-6 Linked List.
CS2013 Lecture 4 John Hurley Cal State LA.
Doubly Linked List Implementation
Recursive Linked List Operations
Lists - I The List ADT.
Lists - I The List ADT.
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Containers: Queue and List
Standard Template Library
STL List.
Data Structures and Algorithms Memory allocation and Dynamic Array
Lists CMSC 202, Version 4/02.
Doubly Linked List Implementation
Standard Template Library
Chapter 3 Lists, Stacks, and Queues
The List Container and Iterators
STL List.
Data Structures & Programming
Presentation transcript:

The List ADT Sections 3.2, 3.3, 3.5 Introduction Welcome to COP 4530, Data Structures, Algorithms, and Generic Programming. I hope very much, and sincerely believe, that this course will change you in ways that are deeply satisfying. So far, you have acquired proficiency in programming. This course will start the process of your transformation from a programmer to a computer scientist. One of the important tasks of a computer scientist is to make efficient use of computational resources. This course will teach you about different ways of organizing the data to facilitate such efficient use, and will also discuss efficient techniques to perform some fundamental operations in computer science. A subsequent course on Algorithms, COP 4531, will teach you to use the techniques discussed in this course to solve commonly encountered computer science problems efficiently. Both these courses will also teach you to analyze the efficiency, and prove the correctness, of your program in a mathematically rigorous manner. Material you learn in these two courses is critical to your becoming a good software developer later.

Lists in Everyday Life Shopping list To-do list Dave Letterman’s top 10 list My cat’s revenge list Shopping vector? What if you want to insert an item?

List Wish List Insert an element Remove an element Remove all items Assignment operator Comparison operators Constructors/destructors Generic class Convenient way to iterate through the list

Abstract view of List and Iterator ListElement next next next next null null prev prev prev prev front I1 back Iterator

List Public Interface (contd) Locating places on the list iterator begin(); const iterator begin() const; iterator end(); const iterator end() const; Accessing values on the list Object & front(); Object & back(); (and their const versions)

List Public Interface (contd.) Write functions int push_front(const Object & x); int push_back(const Object & x); int pop_front(); int pop_back(); int insert(iterator & itr, const Object & x); iterator erase( iterator itr); iterator erase( iterator start, iterator end ); void clear();

List Public Interface (contd.) Constructors and destructor List(); List(const List & rhs); ~List();

List Complexity Requirements O(1) Runtime complexity Default Constructor push_front(t), push_back(t), insert(I, t) pop_front(), pop_back(), erase(I) begin(), end(); front(), back(); empty();

List Complexity Requirements (2) O(N) Runtime complexity Copy Constructor Destructor clear() erase(SI,EI)

List Iterator Public Interface Read-only operators int operator== (const iterator & rhs) const; int operator!= (const iterator & rhs) const; Object& operator* ( ) const; // return a reference to // current value Write operators iterator& operator++ ( ); // prefix iterator operator++ ( int ); // postfix iterator& operator-- ( ); // prefix iterator operator-- ( int ); // postfix O(1) requirement for space and time

Using List List<String> KittyVengeance; KittyVengeance.push_front(“toe biting”); “toe biting” KittyVengeance.push_back(“carpet littering”); “toe biting”, “carpet littering” KittyVengeance.push_front(“midnight howling”); “midnight howling”, “toe biting”, “carpet littering” KittyVengeance.push_back(“couch tearing”); “midnight howling”, “toe biting”, “carpet littering”, “couch tearing” List<String>::iterator I; for (I = KittyVengeance.begin(); I != KittyVengence.end(); I++) { // print list with << }

List Insertion Insert “furniture scratching” before “toe biting” // sequential search for (I = KittyVengeance.begin(); I != KittyVengence.end(); I++) { if (“toe biting” == *I) { break; } // insert the new string KittyVengeance.insert(I, “furniture scratching”); “midnight howling”, “furniture scratching”, “toe biting”, “carpet littering”, “couch tearing” // what happens if “toe biting” is not on the list?

Remove all copies of item from List List<String>::iterator I = KittyVengeance.begin(); while( I != KittyVengeance.end()) { if (“couch tearing” == *I) { KittyVengeance.erase(I); } else { I++; }

List and List Iterator Conceptual relationship Iterator I1 begin current end List: A, B, C, D, E, F begin current end Iterator I2

Nodes in a list Node Defined within the List class, with limited scope Pointers to the previous and next element Data Value Defined within the List class, with limited scope data prev next data prev next data prev next No need for contiguous memory allocation

List Implementation A Doubly Linked List With Header and Tail Nodes as Markers An Empty List

Outline of List Class (Part 1)

Outline of List Class (Part 2)

Outline of List Class (Part 3)

Outline of List Class (Part 4)

const_iterator for List Prefix Postfix

const_iterator class for List (contd.)

iterator class for List Why do we override the parent’s ++ implementation?

iterator class for List (contd.)

List Initialization Routines

List Insert Routine

List Erase Routine