C++ Tutorials | L71: Modifying Sequence Algorithms | C++ STL Best Tutorial | The Easy Concepts

135 Просмотры
Издатель
#competitiveprogramming #placementpreparation #stl
C++ Tutorials | L71: Best Tutorial On Modifying Sequence Algorithms In C++ Standard Template Library | STL In C++ | The Easy Concepts

In this tutorial, we have discussed the concept of a standard template library popularly known as STL. In the previous tutorial, we talked about templates, and here we are going to talk about STL that offers proof of concept for generic programming with templates. STL defines powerful, template-based, reusable components that implement many common data structures (such as lists, stack, arrays, etc.) and algorithms used to process those data structures.

You might have taken data structures and algorithms course at your university but that doesn’t mean that you are an expert and might have implemented all of these on your own or you might not be planning to do so in near future. Without much deeper knowledge of computer science, it’s very difficult to implement an efficient version of these data structures, so STL provides you general-purpose algorithms and containers to make your life easier by the following means -
1. They are correctly implemented and you don’t need to debug or test their efficiency.
2. They are as fast as possible for general use.
3. They are easier to understand and maintain

STL has mainly three components – Containers, Algorithms, and Iterators.
There are 3 types of containers - Sequence Containers, Associative (Non-Linear) Containers (sorted and non-sorted), Container Adapters. The Sequence and Associative as (Non-Linear) Containers are collectively known as first-class containers.

1. Sequence Containers – represent linear data structures such as vectors
and linked contiguous lists. array),
Ex– array (static contiguous array), vector (dynamic contiguous array),
deque (Double-ended queue), list (doubly-linked list), froward_list (singly linked list)

2. Associative (Non-Linear) Containers – Locate elements stored in the
containers quickly. Such containers can store sets of values of key-value
pairs. There are two versions of associative containers, where data is sorted by keys and another where data is not sorted by keys.
Ex – set, map, multiset, multimap

3. Container Adapters – Constrained version of sequential containers or you can say that they provide a different interface for sequential containers.
Ex – stack, queue, priority_queue

Algorithms – STL algorithms can be used generically across a variety of containers. It provides many algorithms you will use frequently to manipulate containers. Inserting, deleting, searching, sorting and others are appropriate for some or all of the STL containers. The algorithms operate on container elements only indirectly through iterators (which you can consider like a loop iterating over a data. We are going to discuss it right after we finish the discussion on algorithms). Many algorithms operate on sequences of elements defined by pairs of iterators – one pointing to the first element of the sequence and one pointing to one element past the last element. Also, it’s possible to create new algorithms that operate in a similar fashion so that they can be used with STL containers and iterators. So we can say that STL is extensible where it’s straightforward to add new algorithms and to do so without changes to STL containers.

Algorithms - Nonmodifying-sequence Algorithms and Mutating-sequence (Modifying) Algorithms

Iterators - Algorithms in STL don’t work on containers, instead they work on iterators, they manipulate the data pointed by the iterators. Thus it doesn't matter what is the type of the container and because of this an algorithm will work for any type of element and we don't have to define the same algorithm for different types of containers.


Please watch the full video to learn the concepts in more detail.

Learn Computer Science Concepts in an Easy Way !!

Website - http://www.theeasyconcepts.com/
Facebook - https://www.facebook.com/theeasyconcepts/
Twitter - https://twitter.com/theeasyconcepts
GitHub - https://github.com/deepakuniyaliit/OOP
LinkedIn - https://www.linkedin.com/in/deepak-uniyal-592b7545/
Telegram - https://t.me/theeasyconcepts
Категория
Язык программирования C++
Комментариев нет.