STL Библиотека стандартных шаблонов

Slides:



Advertisements
Similar presentations
M The University Of Michigan Andrew M. Morgan EECS Lecture 22 Savitch Ch. 16 Intro To Standard Template Library STL Container Classes STL Iterators.
Advertisements

Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
Vectors, lists and queues
Introduction to the STL
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
STL. What is STL? Standard Templates Library Templates are best used for –Defining containers for storing data –Some kinds of algorithms that work the.
What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components.
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.
More on the STL vector list stack queue priority_queue.
Concept= a set of abstractions (e.g., types) (Generic Programming) Programming with Concepts defined by a set of requirements {vector, deque, list, set,
OOP Etgar 2008 – Recitation 101 Object Oriented Programming Etgar 2008 Recitation 10.
The Potential Method. Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Standard Template Library C++ introduced both object-oriented ideas, as well as templates to C Templates are ways to write general code around objects.
Templates and the STL.
Object Oriented Data Structures
STL Standard Template Library ● Good reference book: – The C++ Standard Library ● A Tutorial and Reference ● by Nicolai M. Josuttis ● 1999 – Addison Wesley.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
STL !!!generic programming!!! Anar Manafov
Containers Overview and Class Vector
Containers and Iterators CNS 3370 Copyright 2003, Fresh Sources, Inc.
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
Object Oriented Programming Elhanan Borenstein Lecture #11 copyrights © Elhanan Borenstein.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Templates code reuse - inheritance - template classes template classes - a class that is not data-type specific - eg. a class of Array of any type - intArray,
Chapter 19 C++ Data Structures By C. Shing ITEC Dept Radford University.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Exceptions & Templates
The Standard Template Library Container Classes Version 1.0.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Computer Engineering Rabie A. Ramadan Lecture 6.
1 The Standard Template Library Drozdek Section 3.7.
Properties: -The value in each node is greater than all values in the node’s subtrees -Complete tree! (fills up from left to right) Max Heap.
Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class.
Introduction to Templates and Standard Template Library 1.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
Object-Oriented Programming (OOP) Lecture No. 41
C++ Standard Template Library
Introduction to olympic programming
Data Structures and Algorithms
STL – Standard Template Library
Standard Template Library (STL)
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Programming with Concepts
Lecture 13 – Heaps Container Adapters priority_queue – impl. with heap
priority_queue<T>
Erasmus Exchange in Ionian University
Templates. Templates Example: Swap Template Mechanism.
Design Patterns Difficult to describe abstractly Elements:
Lecture 8 : Intro. to STL (Standard Template Library)
C++ STL Stack, Queue, and Deque
STL (Standard Template Library)
Standard Template Library
C++ Programming: chapter 10 – STL
Standard Template Library
Standard Template Library
Presentation transcript:

STL Библиотека стандартных шаблонов

Алгоритмы sort for_each find count equal swap fill reverse random_shuffle binary_search

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; sort(t,t+size); for(int i=0; i<size; ++i) cout<<t[i]<<" "; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; print(int x){ cout<<x<<" "; } int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; sort(t,t+size); for_each(t,t+size,print);

#include <algorithm> #include <iostream> using namespace std; const int size=10; print(int x){ x*=2; cout<<x<<" "; } int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; sort(t,t+size); for_each(t,t+size,print);

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; cout<<find(t,t+size,0); }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; cout<<find(t,t+size,0)-t; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={2,6,5,8,4,9,1,0,3,7}; cout<<find(t,t+size,11)-t; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,1,1,2,2,1,1,3,3,0}; cout<<count(t,t+size,1); }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,1,1,2,2,1,1,3,3,0}; int m[size]={1,1,1,2,2,1,1,3,3,0}; cout<<equal(t,t+size,m); }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,1,1,2,2,1,1,3,3,0}; int m[size]={1,1,1,2,2,1,1,3,2,1}; cout<<equal(t,t+size,m); }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]; fill(t,t+size,23); for(int i=0; i<size; ++i){ cout<<t[i]<<" "; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,2,3,4,5,6,7,8,9,10}; reverse(t,t+size); for(int i=0; i<size; ++i){ cout<<t[i]<<" "; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,2,3,4,5,6,7,8,9,10}; random_shuffle(t,t+size); for(int i=0; i<size; ++i){ cout<<t[i]<<" "; }

#include <algorithm> #include <iostream> using namespace std; const int size=10; int main(){ int t[size]={1,2,3,4,5,6,7,8,9,10}; cout<<binary_search(t,t+size,2); }

Контейнеры stack queue deque priority_queue list vector set multiset map

STACK empty – стек пуст size – размер стека top – верхний элемент push – добавить элемент pop – удалить элемент

QUEUE empty – очередь пуста size – размер очереди front – верхний элемент push – добавить элемент pop – удалить элемент