Found 7197 Articles for C++

C++ Program to Implement Set in STL

Farhan Muhamed
Updated on 12-May-2025 19:45:46

624 Views

Set is an associative container that stores unique elements in a sorted order. In this article, we will learn how to use the set container from the Standard Template Library (STL) in C++. What is Set? A Set is a container that stores data in a sorted order without any duplicates. Meaning, the duplicate values are automatically eliminated, and the elements are kept in ascending order by default. The STL library of C++ provides a pre-defined set container that uses a balanced binary search tree for storage. For example, in the code we have shown how data are ... Read More

C++ Program to Implement Queue in STL

Farhan Muhamed
Updated on 09-May-2025 15:39:16

871 Views

Queue is a linear data structure that follows the First In First Out (FIFO) principle. In this article, we will learn how to use the queue container from the Standard Template Library (STL) in C++. What is Queue? A Queue is a container that stores data in a sequential way. Meaning, the data that is inserted first to the queue is the one to be removed first from it. This is same as a queue of people where, the person who comes first to the queue will served first. The STL library of C++ provides a pre-defined queue container ... Read More

C++ Program to Implement Priority_queue in STL

Farhan Muhamed
Updated on 12-May-2025 19:46:02

253 Views

Priority Queue is a special type of queue in which elements can be accessed based on their priority. In this article, we will learn how to use the priority_queue container from the Standard Template Library (STL) in C++. What is Priority Queue? A Priority Queue is a container that stores data in such a way that the highest (or the lowest) priority element will always at the front of queue. Meaning, a priority queue does not follow FIFO rule of a regular queue, it processes elements based on ceratin priority. This priority can be defined as highest elements at ... Read More

C++ Program to Implement Prev_Permutataion in STL

Farhan Muhamed
Updated on 09-May-2025 15:39:04

163 Views

The Prev permutation is an algorithmic operation that rearranges the elements of an array or a range of an array into the previous lexicographically smaller permutation. In this article, we will learn how to use the prev_permutation() function from the Standard Template Library (STL) in C++. What is Prev Permutation? The Prev Permutation is an operation used to generate all the possible permutations of an array in reverse lexicographical order. A permutation is one of the N! arrangements of the elements in an array of size N. The STL library of C++ provide a pre-defined function for performing the ... Read More

C++ Program to Implement Pairs in STL

Farhan Muhamed
Updated on 09-May-2025 15:38:46

445 Views

A pair is a container provided by the Standard Template Library (STL) in C++ that stores two heterogeneous objects as a single unit. In this article, we will learn how to use a pair from the Standard Template Library (STL) in C++. What is Pair? Pair is a utility container defined in the header that is used to store two related data elements or objects in pairs. The first element will be referenced as first, and the second element will be referenced as second. It is commonly used to return two values from a function using a single ... Read More

C++ Program to Implement Next_Permutation in STL

Farhan Muhamed
Updated on 09-May-2025 15:38:15

436 Views

Next permutation is an algorithmic operation that rearranges the elements of a range into the next lexicographically greater permutation. In this article, we will learn how to use the next_permutation() function from the Standard Template Library (STL) in C++. What is Next Permutation? The Next Permutation is an operation used to generate all the possible permutations an array in lexicographical order. A permutation is the one of N! arrangements of the elements in an array of size N. If the current sequence is the last permutation, the function transforms it into the first one (i.e., sorted in ascending order). ... Read More

C++ Program to Implement Multiset in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:43

270 Views

A multiset is an associative container that stores data in a sorted order in such a way that it allows duplicate values in the set. In this article, we will learn how to use a multiset from the Standard Template Library (STL) in C++. What is Multiset? Multiset is a sorted associative container that allows storing multiple elements with the same value. The values are automatically arranged in sorted order. This makes it useful in scenarios where you need to keep count of repeated values while maintaining order. For example, we can store the scores of students even ... Read More

C++ Program to Implement Multimap in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:29

435 Views

A multimap is an associative container that stores elements in a key-value pair format, where multiple values can share the same key. In this article, we will learn how to use a multimap from the Standard Template Library (STL) in C++. What is Multimap? Multimap is a sorted associative container that stores data in key-value pairs, where keys can occur multiple times. Keys are stored in sorted order, and you can insert, access, and remove elements based on the key. For example, in a multimap we can store student names with their scores even if some students have ... Read More

C++ Program to Implement Map in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:15

4K+ Views

A map is an associative container that stores elements in a key-value pair format. Each element has a unique key and a corresponding mapped value. No two mapped values can have the same key. In this article, we will learn how to use a map from the Standard Template Library (STL) in C++. What is Map? Map is a sorted associative container that contains key-value pairs with unique keys. Keys are sorted automatically, and each key is associated with a value. You can insert, access, and remove elements based on the key. For example, we can store ... Read More

C++ Program to Implement List in STL

Farhan Muhamed
Updated on 06-May-2025 18:21:17

395 Views

A List in C++ STL library is hardcoded implementation of a doubly linked list data structure. In this article, we will learn how to implement and use a list in C++ . What is List? List is a doubly linked container provided in the C++ STL library, in which each element points to both its previous and next elements. Meaning, in this list we can quickly traverse in both forward and backward direction using pointers just like a doubly linked list. Compared to vectors or arrays, these lists allow fast insertions and deletions from the middle of the sequence. ... Read More

Advertisements