C++ STL List Container C++ STL list container Examples

Slides:



Advertisements
Similar presentations
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
Advertisements

Linked Lists. 2 Merge Sorted Lists Write an algorithm that merges two sorted linked lists The function should return a pointer to a single combined list.
Computer Science 209 Software Development Equality and Comparisons.
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
Binary Search Trees CMSC 132 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
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.
CS 146: Data Structures and Algorithms June 18 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
Data Structures Using C++ 2E
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
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.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
The List ADT Reading: Sections 3.2, 3.3, 3.5.
CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
 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.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Given a node v of a doubly linked list, we can easily insert a new node z immediately after v. Specifically, let w the be node following v. We execute.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
CSE 1342 Programming Concepts
Unit – I Lists.
Iterators and Sequences
5.13 Recursion Recursive functions Functions that call themselves
UNIT – I Linked Lists.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Chapter 4 Linked Lists.
Binary Search Trees Why this is a useful data structure. Terminology
Lab 10 - Quicksort.
Wednesday, April 11, 2018 Announcements… For Today…
Object Oriented Programming COP3330 / CGS5409
Heapsort Heap & Priority Queue.
C++ STL Vector Container
CSC212 Data Structure - Section RS
A simpler implementation and analysis of Chazelle’s
Array Techniques Unit 4.
Recitation Outline C++ STL associative containers Examples
Divide-And-Conquer-And-Combine
Doubly Linked List Implementation
Recursive Linked List Operations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Linked List and Selection Sort
Chapter 17: Linked Lists.
MTree An implementation and An example with m=3
Maintaining Dynamic Tree with Min Subject to Constraints
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
C++ STL Stack, Queue, and Deque
Podcast Ch18d Title: Binary Search Tree Iterator
Lists - I The List ADT.
General List.
Lists - I The List ADT.
Doubly Linked List Implementation
List Operation in ProLog EUSL/TC/IS/2013/COM/08. In here list will print..
Recitation Outline Hash tables in C++ STL Examples Recursive example
A dictionary lookup mechanism
Presentation transcript:

C++ STL List Container C++ STL list container Examples Word puzzle using C++/STL list container STL list is used to maintain the word dictionary Maximum subsequence program

Important C++ STL list container interface size() empty() clear() front()/back() push_back()/push_front() pop_back()/pop_front() insert(i, x) erase(i), erase(start, end) begin()/end() remove() List<T>::iterator/List<T>::const_iterator

Import list member functions reverse(): reverse elements in list sort(): sort elements in list Stable sort (relative order of equal elements are respected) uniqe(): remove duplicate elements Example: delete duplicate elements remove_duplicate.cpp

Word Puzzle Word puzzle program has been re-written to use C++ STL list container to maintain the word list All other parts are the same as the first implementation as STL vector See examples/r4 word_puzzle_list.h word_puzzle_list.cpp rotation.cpp Makefile words.txt // word dictionary puzzle1.txt // a puzzle Review the code A demo of running the program

MSS: Maximum SubSequence Problem Computing maximum subsequence as given in the textbook See examples/r4 Mss_problem.txt // problem description Mss.cpp // source code Mss.input1 Mss.output1 To compile: make mss.x Review the code A demo of running the program

size() of List: Recursive Implementation A problem to consider Assuming that we do not maintain theSize member variable, how do we determine the number of elements in a list using a recursive function? See examples/r4 list_size1.cpp (using Node pointer) list_size2.cpp (using iterator) Note that in essence, they are the same