Found 7346 Articles for C++

C++ Program to Implement Set_Intersection in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

469 Views

The intersection of two sets is formed only by the elements those are common in both sets. The elements copied by the function come always from the first set in the same order. The elements in the both the sets shall already be ordered.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.    Initialize st = set_intersection (set1, set1 + n, set2, set2 +n, v.begin()))    Print the intersection between two sets. End.Example Code#include #include #include using namespace std; int main () {   ... Read More

C++ Program to Implement Set_Difference in STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

738 Views

The difference of two sets is formed only by the elements that are present in the first set, not in the second set. The elements copied by the function come always from the first set in the same order. The elements in both the sets shall already be ordered.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.    Initialize st = set_difference (set1, set1 + n, set2, set2 +n, v.begin()))    Print the number of elements different between two sets. End.Example Code#include #include #include using ... Read More

C++ Program to Implement Set in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

461 Views

Set is abstract data type in which each element has to be unique, because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, but it is possible to remove and add the modified value of that element.Functions and descriptions:Functions used here:    st.size() = Returns the size of set.    st.insert() = It is used to insert elements to the set.    st.erase() = To delete the element from the set.    st.find() = Returns an iterator to the search element in the set if found, else ... Read More

C++ Program to Implement Queue in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

628 Views

A queue is a linear structure which follows First In First Out (FIFO) order in which the operations are performed on the elements of the queue.AlgorithmFunctions used here:    q.size() = Returns the size of queue.    q.push() = It is used to insert elements to the queue.    q.pop() = To pop out the value from the queue.    q.front() = Returns the front element of the array.    q.back() = Returns the back element of the array.Example Code#include #include #include #include using namespace std; int main() {    queue q;    int c, i;    while (1) {       cout

C++ Program to Implement Priority_queue in STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

92 Views

Priority queues are a type of container adapters, in which the first element of the queue is the greatest of all elements in the queue. Elements are in also non decreasing order in the priority queue. An element with high priority is served before an element with low priority, in a priority queue.Functions and descriptions:Functions used here:    pq.size() = Returns the size of priority queue.    pq.insert) = It is used to insert elements to the priority queue.    pq.delete() = Deletes the value from the priority queue.    pq.top() = Returns a reference to the top most element ... Read More

C++ Program to Implement Prev_Permutataion in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

77 Views

Prev_permutation in STL is used to rearrange the elements in the range [first, last] into the previous lexicographically smaller permutation. A permutation is each one of the N! possible arrangements the elements can take. Here is a C++ program to implement Prev_permutation in STL.AlgorithmBegin    Define one integer array variable elements[].    Get the number of data e from the user.    Initialize the array elements[] with e number of data from the keyboard.    Sort all the array elements.    Reverse the array elements.    Do       show(elements) //to display the current content of the array   ... Read More

C++ Program to Implement Pairs in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

266 Views

Pair is a simple container which consists of two data object:‘first’ = The first element is referenced as ‘first’ ‘second’ = the second element and the order is fixed (first, second).Pair can be assigned, compared and copied. It is used to combine together two values which may be different in type.Syntax is: pairvariable name(datavalue1, datavalue2).AlgorithmBegin Write pairvariable name(datavalue1,datavalue2) Print the pairs EndExample Code#include using namespace std; int main() { pair value('a',7); pair fruit ("grapes",2.30); pair food ("pulao",200); cout

C++ Program to Implement Next_Permutation in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

273 Views

Next_permutation in STL is used to rearrange the elements in the range [first, last] into the next lexicographically greater permutation. A permutation is each one of the N! possible arrangements the elements can take. This is C++ program to implement Next_permutation in STL.AlgorithmBegin    Define one integer array variable elements[].    Get the number of data e from the user.    Initialize the array elements[] with e number of data from the keyboard.    Sort all the array elements.    do       show(elements, e) //to display the current content of the array    while (next_permutation(elements, elements + e)) ... Read More

C++ Program to Implement Multiset in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

145 Views

A multiset is a type of associative container in which has multiple elements can have same values.Functions and descriptions:Functions are used here:    ms.size() = Returns the size of multiset.    ms.insert) = It is used to insert elements to the multiset.    ms.erase() = Removes the value from the multiset.    ms.find() = Returns an iterator to the search element in the multiset if found,    else returns the iterator to end.    ms.count() = Returns the number of matches element in the multiset.    ms.begin() = Returns an iterator to the first element in the multiset.    ms.end() ... Read More

C++ Program to Implement Multimap in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

315 Views

Multimap is similar to map with an exception that multiple elements can have same keys. The key value and mapped value pair has to be unique in multimap.Function is used here -mm::find() – Returns an iterator to the element with key value ‘b’ in the multimap if found, else returns the iterator to end.mm::erase() – Removes the key value from the multimap.mm:: equal_range() – Returns an iterator of pairs. The pair refers to the bounds of a range that includes all the elements in the container which have a key equivalent to key.mm insert() – To insert elements in the ... Read More

Advertisements