Your SlideShare is downloading. ×
Stl (standard template library)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Stl (standard template library)

747
views

Published on

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
747
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PERSTATION ON (STL) Standard Template Library BY HEMANT JAIN ROLL NO. 22
  • 2. Standard Template Library
    • Introduction :- STL stands for “ Standard Template Library ”
    • The STL provides a ready-made set of common classes for C++, such as containers and associative arrays,
    • that can be used with any built-in type and with any user-defined type that supports some elementary operations (such as copying and assignment).
  • 3.
    • The STL achieves its results through the use of templates. This approach provides compile-time polymorphism that is often more efficient than traditional run-time polymorphism.
    • Modern C++ compilers are tuned to minimize any abstraction penalty arising from heavy use of the STL.
  • 4. STL (Standard Template Library) Algorithms Container Classes A library of class and function templates based on work in generic programming done by Alex Stepanov and Meng Lee of the Hewlett Packard Laboratories in the early 1990s. vector sort() begin() end() Iterates
  • 5. Standard Template Library
    • The STL is a collection of generic classes and functions. It has three components:-
    • (1). Containers are data structures that store data.
    • Generic "off-the-shelf“ class templates for storing collections of data .
    • (2). Algorithms are procedures used to process data contained in containers.
    • Generic "off-the-shelf" function templates for operating on containers
    • (3). Iterates are object (pointer) that points to elements in a container. Generalized "smart" pointers that allow algorithms to operate on almost any container.
  • 6.                                                
  • 7. (1). Containers
    • The STL contains sequence containers and associative containers .
    • The standard sequence containers include vector , deque , and list .
    • The standard associative containers are set , multiset , map , and multimap .
    • There are also container adaptors queue , priority_queue , and stack , that are containers with specific interface, using other containers as implementation.
  • 8. STL's Containers In 1994, STL was adopted as a standard part of C++. There are some containers in STL: Kind of Container STL Containers Sequential: deque , list , vector Associative: map , multimap , multiset , set Adapters: priority_queue , queue , stack Non-STL: bitset , valarray , string
  • 9. Containers
    • Sequence containers
      • Store elements in linear sequence. Ex – array , vector , list , deque.
    • Associative containers
      • Used to automatically arrange stored data in a specific order. Uses trees. Ex – set , multiset , map , multimap .
    • Container Adapters / Derived Containers
      • Special purpose containers created from normal containers
  • 10. Sequence Containers Ex. vector<int> v1; vector<int>iterator iter; Random Quick random access, slow insertion/deletion in middle, size can not be changed at runtime array Iterator Description Container Random Double ended queue, direct access, slow insert/delete in middle, fast at beg/ end deque Bidir. Doubly link list, fast insert/delete anywhere, slow random access list Random Dynamic array, quick random access, slow insertion/deletion in middle, fast at back vector
  • 11. Associative Containers Ex. set<int> s1; Bidir. Stores key-value pair, Unique keys, one-to-one mapping Map Iterator Description Container Bidir. Stores key-value pair, Multiple keys, one-to-many mapping Multimap Bidir. Stores non-unique key objects Multiset Bidir. Stores unique key objects, allows rapid look up Set
  • 12. Derived Containers/Container Adapters Ex. stack <deque<int> > s1; Iterator Description Container None Element of highest priority popped. Create from vector or dequeue Priority -queue None FIFO. Create from list or dequeue Queue None LIFO. Create from vector, list or dequeue Stack
  • 13. (2). Iterators
    • The STL implements five different types of iterators . These are
    • 1. input iterators (that can only be used to read a sequence of values),
    • 2.output iterators (that can only be used to write a sequence of values),
    • 3. forward iterators (that can be read, written to, and move forward),
    • 4. bidirectional iterators (that are like forward iterators, but can also move backwards) &
    • 5. random access iterators (that can move freely any number of steps in one operation).
  • 14. Iterators
  • 15. Algorithms
    • A large number of algorithms to perform operations such as searching and sorting are provided in the STL, each implemented to require a certain level of iterator (and therefore will work on any container that provides an interface by iterators).
  • 16. Algorithms
    • Find() – search first element with specified value.
    • int arr[ ]={1,2,3,4,5,6,7,8};
    • int * ptr = find(arr,arr+8,3);
    • count() - counts occurrences of a specified element
    • int n=count(arr,arr+8,3);
    • sort()
    • sort(arr,arr+8);
  • 17.
    • search( ) - looks for a sequence of values, specified by one container within another container
    • int s[ ]={1,2,3,4,5,1,2,3};
    • int p[ ]={1,2,3};
    • int *pt=search(s,s+8,p,p+3);
    • merge( ) - merges 2 source containers into third
    • merge(src1,src1+5,src2,src2+5,dest);
  • 18. STL SEQUENCE CONTAINERS CONTAINER ADAPTORS ASSOCIATIVE CONTAINER OTHER CONTAINERS VECTOR LIST DEQUE QUEUE PRIORITY_ QUEUE STACK SET HASH_SET MULIT_SET HASH_MULTISE T MAP HASH_MAP MULITMAP HASH_MULITMAP BITSET VALARRAY
  • 19. THANK YOU....