
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

131 Views
Given is the task to show the working of list crbegin() and crend() functions in C++.The list::crbegin() and list::crend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::crbegin()This function returns the constant iterator which points to the end element of the list which will be the reverse beginning of the list. It can be used for Backtracking the list but it cannot change the values in the list which means crbegin() function can be used for iteration only.SyntaxList_Name.crbegin()ParametersThe function does not accept any parameter.Return ValueThe function returns a constant reverse ... Read More

139 Views
Given is the task to show the working of list::cbegin() and list::cend functions in C++.The list::cbegin() and list::cend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::cbegin()This function returns the constant iterator which points to the beginning element of the list. It can be used to traverse the list but it cannot change the values in the list which means cbegin() function can be used for iteration only.SyntaxList_Name.cbegin();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that point at the beginning element of the list.list::cend()This function ... Read More

255 Views
Given is the task to show the working of list back() function in c++.The list::back() function is a part of the C++ standard template library. It is used to display the last element of any list. header file should be included before calling this function.SyntaxList_Name.back();ParametersThe function does not accept any parameter.Return ValueThe function returns the value of the last element of the list.ExampleInput: Lt.assign(3, 10) Lt.back() Output: 10Explanation − The following example shows how we can find the last value of any list by using the back() function. The list Lt is assigned three elements, each with value 10 and ... Read More

297 Views
Given the task is to show the working of deque::assign() in C++ STL.Deque is a double ended queue. In C++, deque::assign() is an inbuilt function which is used to assign the new value to the deque container. Every time this function is called it assigns a new value to the deque container by replacing the existing values and changing the size allocated accordingly.SyntaxSyntax of deque::assign() is as follows −dequename.assign( size, val)ParametersThis function includes 2 parameters −First is the size, which represents the size of the deque container and the second one is val, which is the value contained by ... Read More

807 Views
strstr() function is a predefined function in “string.h” header file which is used for performing string handling. This function is used to find the first occurrence of a substring let’s say str2 in the main string let’s say str1.SyntaxSyntax of strstr() is as follows −char *strstr( char *str1, char *str2);Parameters of strstr() arestr2 is the substring which we wish to search in the main string str1Return value of strstr() isThis function returns the address pointer of the first occurrence of the substring which we are searching if found in the main string, else it will return a null when the ... Read More

322 Views
Suppose we have an integer n. We have to return any array that contains n unique integers, such that they add up to 0. So if input is n = 5, then one possible output will be [-7, -1, 1, 3, 4]To solve this, we will follow these steps −take an array A as final answer, and take x := 0for i in range 0 to n – 2A[i] = (i + 1)x := x + i + 1A[n – 1] = xreturn AExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){ cout

416 Views
Suppose we have an array A. We have to replace every element by the greatest element on the right side of this element. And replace the last one by -1. So if A = [5, 17, 40, 6, 3, 8, 2], then it will be [40,40,8,8,8,2,-1]To solve this, we will follow these steps −We will read the array element from right to left.take e := -1for i := n – 1 to 0temp := ee := max between e and array[i]array[i] := tempreturn arrayExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){ cout

278 Views
Suppose we have an array A. There are few elements. Some elements are common. We have to return an element that is appearing more than 25% spaces in the array. So if A = [1, 2, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7], Here 4 has occurred four times. This is more than 25% of 12 (size of the array)To solve this, we will follow these steps −Read elements and store their respective frequenciesIf the frequency is greater than 25% of the array size, then return the result.ExampleLet us see the following implementation to get better understanding ... Read More

487 Views
Suppose we have one number. We have to find the sum of digits and product of digits. After that find the difference between sum and product. So if the number is 5362, then sum is 5 + 3 + 6 + 2 = 16, and 5 * 3 * 6 * 2 = 180. So 180 – 16 = 164To solve this take each digit and add and multiply one by one, then return the difference.ExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; class Solution { public: int subtractProductAndSum(int n) { int prod = 1; int sum = 0; for(int t = n;t;t/=10){ sum += t % 10; prod *= t % 10; } return prod - sum; } }; main(){ Solution ob; cout

234 Views
Suppose there are some points given as an array. We have to find the minimum time in seconds to visit all points. There are some conditions.In one second, it can move vertically, horizontally and diagonallyWe have to visit the points in the same order as they appear in the array.So if the points are [(1, 1), (3, 4), (-1, 0)], then output will be 7. If we check the sequence for the shortest route, the sequence will be (1, 1), (2, 2), (3, 3), (3, 4), (2, 3), (1, 2), (0, 1), (-1, 0)To solve this we will just find ... Read More