Found 7401 Articles for C++

C++ Program to Implement Next_Permutation in STL

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

252 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

129 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

290 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

C++ Program to Implement Map in STL

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

3K+ Views

A Map is an associative container that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have same key values.Functions are used here:m::find() – Returns an iterator to the element with key value ‘b’ in the map if found, else returns the iterator to end.m::erase() – Removes the key value from the map.m:: 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.m insert() – To insert ... Read More

C++ Program to Implement List in STL

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

220 Views

A list is a sequence container that allow non-contiguous memory allocation. List has slow traversal as compared to vector, but once a position has been found, insertion and deletion are quick.Functions and descriptions:From main(), we have called following functions:    fl.resize() = Returns the resize of list.    fl.push_front() = It is used to push elements into a list from the front.    fl.remove() = Deletes elements from list.    fl.unique() = Deletes duplicate elements from list.    fl.reverse() = Reverses the list.    fl.front() = Returns the front element of list.Example Code#include #include #include #include using ... Read More

C++ Program to Implement Forward_List in STL

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

160 Views

Forward list in STL implements singly linked list. List is different by forward_list that list keeps track to both next and previous elements.While forward list keeps track of location of only next elements, thus increasing the storage space required to store each element. The disadvantage of forward_list is that is individual elements cannot be accessed directly and it cannot be iterated backwards.Functions and descriptions:From main(), we have called following functions:    fl.resize() = Returns the resize of forward_list.    fl.push_front() = It is used to push elements into a foward_list from the front.    fl.remove() = Deletes elements from forward_list. ... Read More

C++ Program to Implement Deque in STL

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

325 Views

Double Ended Queue is a Queue data structure in which the insertion and deletion operations are performed at both the ends (front and rear). Data can be inserted at both front and rear positions and can be deleted from both front and rear positions.AlgorithmBegin Declare deque vector and iterator. Take the input as per choice. Call the functions within switch operation: d.size() = Returns the size of queue. d.push_back() = It is used to push elements into a deque from the back. ... Read More

Binary Search functions in C++ STL

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

712 Views

Binary search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the sorted array. The time complexity of binary search is O(1). This is a C++ program in which we implement various. Binary Search functions in C++ STLAlgorithmBegin    Initialize the vector of integer values.    The functions are used here:    binary_search(start_pointer, end_pointer, value) = Returns true if the value present in array otherwise    false.    lower_bound(start_pointer, end_pointer, value) = Returns pointer to “position of value” if container ... Read More

4 Dimensional Array in C/C++

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

655 Views

A 4 dimensional array is an array of 3Darrays.AlgorithmBegin. Declare the variables. Declare the array elements. Take the no of elements as input. Take the elements as input. Print the elements stored in array. End.Here is an example of 4D array.#include using namespace std; int main() {    int a[2][2][3][2];    cout > a[i][j][k][l];             }          }       }    }    cout

Why C/C++ array index starts from zero?

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

550 Views

As Array index starts with 0, so a[i] can be implemented as *(a + i).If Array index starts with 1 then a[i] will be implemented as *(a+i-1) which will be time consuming during compilation and the performance of the program will also be effected.So, it is better to start index of the array from 0.A simple program of array is given -Example Codeint main() {    int array[5] = {7, 7, 7, 6, 6};    for (int i = 0; i < 5; i++)       cout

Advertisements