c what are some templated data structures from the standard

c++ what are some templated data structures from the standard template library?
c++ what are some templated data structures from the standard template library?
c++ what are some templated data structures from the standard template library?

Solution

In C++, Standard template library is basically the libary consisting of classes, algorithms and the iterators. It provides the users with the set of tools and the facilities ( basic algoritms and the data structures) that can be used for many applications. It offers the user various advantages in addition to the memory management. Firstly, having the predefined data type simplies the program design, user don\'t have the write the same the classes again and again for handling the arrays, linked list,queues. Secondly it provides the powerful type independent algorithms , including sorting and searching.It inhances the performance of the program and it is also less likely that using templates will lead to bugs than using the own code.

The 3 componets of the Standard template library of c++ are :-

1) Containers :- they are used to manage the collection of objects of the certain kind. various types of the containers are list, vector , map.

2) Algorithms :- They work on containers.They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers.

3) Iterators:- They are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.

For Example:-

In this example :-

The algorithm copy copies elements from one container to another. Here the target is the standard output stream cin made to look like a container of strings

Example:-

When the above code is compiled and executed, it produces the following result:

The push_back( ) member function inserts value at the end of the vector, expanding its size as needed.

The size( ) function displays the size of the vector.

The function begin( ) returns an iterator to the start of the vector.

The function end( ) returns an iterator to the end of the vector.

Stacks

Stacks are only accessed at their top. To be able to use STL stacks in a file of C++ source code or a header file \"add #include <stack>\" at the beginning of the file.Suppose that T is any type or class - say an int, a float, a struct, or a class, then

stack<T> s; declares a new and empty stack called s.

To find how many items are in it, use the function size:

To push a item t of type T onto the top, use the function push:

To pop the top off s:

To get the top item of s

To test to see if it is empty:

Queues

Queues allow data to be added at one end and taken out of the other end. To be able to use queues add this before you start using them in your source code:

Suppose that T is any type or class - say an int, a float, a struct, or a class, then

To test to see if q is empty:

To find how many items are in q:

To push a t:T onto the end of q:

To pop the front of q off q:

To get the front item of q:

To change the front item:

To get the back item of q:

To change the back item:

Lists

Lists are used when data needs to be reorganized a lot. To be able to use lists add this before you start using them in your source code: #include <list>

Suppose that T is any type or class - say an int, a float, a struct, or a class, then

declares a new and empty list called l. Given an object l:

To reverse the list:

To assign a copy of q1 to q:

To merge in a sorted list into a sorted list:

l.merge(list_of_sorted_elements)

To clear the list:

To sort the list:

To test to see if l is empty:

To find how many items are in l:

To push a t:T onto the end of l:

To pop the last off l:

To push a t:T onto the start of l:

To pop the front of l off l:

To get the front item of l:

 c++ what are some templated data structures from the standard template library? c++ what are some templated data structures from the standard template library?
 c++ what are some templated data structures from the standard template library? c++ what are some templated data structures from the standard template library?

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site