Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.

Slides:



Advertisements
Similar presentations
Chapter 25 Lists, Stacks, Queues, and Priority Queues
Advertisements

Slide 1 Insert your own content. Slide 2 Insert your own content.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Report Card P Only 4 files are exported in SAMS, but there are at least 7 tables could be exported in WebSAMS. Report Card P contains 4 functions: Extract,
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.
Chapter 17 Linked Lists.
Lists Briana B. Morrison Adapted from Alan Eugenio & William J. Collins.
COMP171 Fall 2005 Lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Linked Lists.
1 Linked lists Sections 3.2, 3.3, 3.5 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors.
Linked Lists Chapter 4.
1/27 COP 3540 Data Structures with OOP Chapter 5 Linked Lists.
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
ITEC200 Week04 Lists and the Collection Interface.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Alan YorinksLecture 7 1 • Tonight we will look at:: • List ADT • Unsorted List • Sequential Search • Selection Sort • Sorted List • Binary Search.
Data Structures Using C++
Double-Linked Lists and Circular Lists
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
1 Joe Meehean. Ordered collection of items Not necessarily sorted 0-index (first item is item 0) Abstraction 2 Item 0 Item 1 Item 2 … Item N.
ABC Technology Project
1 DATA STRUCTURES. 2 LINKED LIST 3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be.
CSCI2100B Linked List Jeffrey
CSE Lecture 12 – Linked Lists …
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Review Pseudo Code Basic elements of Pseudo code
Linked Lists.
Linked Lists.
The List ADT Textbook Sections
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Chapter 5 Test Review Sections 5-1 through 5-4.
Addition 1’s to 20.
25 seconds left…...
Week 1.
We will resume in: 25 Minutes.
Stack & Queues COP 3502.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Pointers and Linked Lists.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
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.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.
Containers Overview and Class Vector
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
1 Circular, Doubly-Linked Lists Node Composition List Class Pushing and Popping Values Insert and Erase at Arbitrary Locations List Implementation.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
Associative Structures
STL List.
The List Container and Iterators
STL List.
Presentation transcript:

Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample list Sample list The list ADT The list ADT CLASS list Constructors CLASS list Constructors CLASS list OperationsCLASS list Operations CLASS list Operations (7 slides) CLASS list Operations CLASS list::iterator Operations CLASS list::iterator Operations Inserting an element into a list Inserting an element into a list Removing an element from a list Removing an element from a list Ordered lists Ordered lists Splicing two lists Splicing two lists Summary SlidesSummary Slides Summary Slides (5 slides) Summary Slides Chapter 6 – The List Container and Iterators

Main Index Contents 2 Shifting blocks of elements to insert or delete a vector item

Main Index Contents 33 Main Index Contents Model of a list object with links to next and previous element

Main Index Contents 4 Sample list

Main Index Contents 55 Main Index Contents The List ADT The list API documents the member function prototype as well as pre- and postconditions. – provides three constructors to declare a list object.

Main Index Contents 66 Main Index Contents CLASS list Constructors list(); Create an empty list. This is the default constructor. list(int n, const T&value = T()); Create a list with n elements, each having a specified value. If the value argument is omitted, the elements are filled with the default value for type T. Type T must have a default constructor, and the default value of type T is specified by the notation T(). list(T *first, T *last); Initialize the list, using the address range [first, last).

Main Index Contents 77 Main Index Contents CLASS list Operations T& back(); Return the value of the item at the rear of the list. Precondition: The vector must contain at least one element. bool empty() const; Return true if the vector is empty, false otherwise. T& front(); Return the value of the item at the front of the list. Precondition: The vector must contain at least one element.

Main Index Contents 88 Main Index Contents CLASS list Operations void push_back(const T& value); Add a value at the rear of the list. Postcondition: The list has a new element at the rear, and its size increases by 1. void pop_back(); Remove the item at the rear of the list. Precondition:The list is not empty. Postcondition:The list has a new element at the rear or is empty.

Main Index Contents 99 Main Index Contents CLASS list Operations void push_front(const T& value); Add a value at the front of the list. Postcondition:The list has a new element at the front, and its size increases by 1. void pop_front(); Remove the item at the front of the list. Precondition:The list is not empty. Postcondition:The list has a new element at the front or is empty. int size() const; Return the number of elements in the vector.

Main Index Contents 10 Main Index Contents CLASS list Operations iterator begin(); Returns an iterator that references the first position (front) of the list. If the list is empty, the iterator value end() is returned. const_iterator begin(); Returns a const_iterator that points to the first position (front) of a constant list. If the list is empty, the const_iterator value end() is returned. iterator end(); Returns an iterator that signifies a location immediately out of the range of actual elements. A program must not dereference the value of end() with the * operator.

Main Index Contents 11 Main Index Contents CLASS list Operations iterator end(); Returns an iterator that signifies a location immediately out of the range of actual elements. A program must not dereference the value of end() with the * operator. const_iterator end(); Returns a const_iterator that signifies a location immediately out of the range of actual elements in a constant list. A program must not dereference the value of end() with the * operator.

Main Index Contents 12 Main Index Contents CLASS list Operations void erase(iterator pos); Erase the element pointed to by pos. Precondition:The list is not empty. Postcondition:The list has one fewer element. void erase(iterator first, iterator last); Erase all list elements within the iterator range [first, last]. Precondition:The list is not empty. Postcondition:The size of the list decreases by the number of elements in the range.

Main Index Contents 13 Main Index Contents CLASS list Operations iterator insert(iterator pos, const T& value); Insert value before pos, and return an iterator pointing to the position of the new value in the list. The operation does not affect any existing iterators. Postcondition:The list has a new element.

Main Index Contents 14 Main Index Contents CLASS list::iterator Operations * :Accesses the value of the item currently pointed to by the iterator.*iter; ++ :Moves the iterator to the next item in the list.iter++; -- :Moves the iterator to the previous item in the list.iter--; == :Takes two iterators as operands and returns truewhen they both point at the same item in the list. iter1 == iter2 != :Returns true when the two iterators do not point at the same item in the list. iter1 != iter2

Main Index Contents 15 Main Index Contents Inserting an element into a list

Main Index Contents 16 Removing an element from a list

Main Index Contents 17 Main Index Contents Ordered lists Position the iterator curr at the front of the list. Insert 50 in the list:

Main Index Contents 18 Main Index Contents Splicing two lists

Main Index Contents 19 Main Index Contents Summary Slide 1 §- list -A Sequence of elements stored by position. -Index access is not available… §-to access the value of an element, must pass through its preceding elements. §- list iterator -A generalized pointer that moves through a list element by element… forward or backward -At any point, the * operator accesses the value of a list item.

Main Index Contents 20 Main Index Contents Summary Slide 2 §- The list class has two iterator types: 1)iterator 1)iterator: A generalized list traversal pointer. 2)const_iterator 2)const _ iterator: :: must be used with a constant list object. Each type is a nested class of list and must be accessed by using the scope operator ::

Main Index Contents 21 Main Index Contents Summary Slide 3 §- the list member function begin() -Gives an iterator an initial value that points to the first element. §- the list member function end() -Returns an iterator pointing just past the last element of the list.

Main Index Contents 22 Main Index Contents Summary Slide 4 §- The sequential search of a list object firstlast -implemented by using an iterator range [first, last). last -It returns an iterator that points at the target value or has value last if the target is not in the list.

Main Index Contents 23 Main Index Contents Summary Slide 5 §- list class member f ns insert() and erase() -Both use an iterator argument to modify a list. 1)insert() pos 1)insert(): places value in the list before the data referenced by the iterator pos. 2)erase() pos 2)erase(): removes the data item referenced by pos from the list.