Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Page 239 of 597
Evaluate Reverse Polish Notation in C++ Program
Suppose we have Reverse polish notation and we have to evaluate the value. The reverse polish notation is also known as postfix expression. Here we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from stack and then the operation is performed in the correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack top. So ...
Read MorePrint all the duplicates in the input string in C++
In this problem, we are given a string and we have to find all the characters that are duplicated along with their number of occurrences in the string.Let’s take an example to understand the problem −Input: TutorialsPoint Output: t (3) o (2) i (2)Explanation− The frequencies of occurrence of each character are t → 3; u → 1; o → 2; r → 1; i → 2; a → 1; s → 1; n → 1.Now, to solve this problem we will find the character count and store it in an array from the string. And then print the characters ...
Read MoreSorting string in Descending order C++
The sorting in ascending or descending order, however, can duly be performed by using string sort method and other means too in the C++ programming. But here, the string compare (first words with the second) and copy (copy the first word in a temp variable) method involved in the inner and outer traversing loop to put the words in descending order as following.Example#include using namespace std; int main(){ char str[3][20]={"Ajay","Ramesh","Mahesh"}; char t[20]; int i, j; for(i=1; i
Read MorePrint all the combinations of a string in lexicographical order in C++
In this problem, we are given string str, and we have to print all the combinations of the characters in a lexicographical order.Let’s take an example to understand the problem better −Input: str = ‘XYZ’ Output : X XY XYZ XZ XZY Y YX YXZ YZ YZX Z ZX ZXY ZY ZYXTo solve this problem, we will print all the combinations of characters in the string. For this, we need a map data structure to store the characters of the string. For the implementation, we will need to use backtracking to keep track of all combinations.Example#include using namespace std; ...
Read MorePrint all subarrays with 0 sum in C++
In this problem, we are given an array of integer values and we have to print all those subarrays from this array that have the sum equal to 0.Let’s take an example to understand the topic better, Input: array = [-5, 0, 2, 3, -3, 4, -1] Output: Subarray with sum 0 is from 1 to 4. Subarray with sum 0 is from 5 to 7 Subarray with sum 0 is from 0 to 7To solve this problem, we will check all subarrays possible. And check if the sum of these subarrays is equal to 0 and print them. This ...
Read MorePrint all subsequences of a string using Iterative Method in C++
In this problem, we are given a string and we have to find the substring from the given string. The substring to be found should start with a vowel and end with constant character.A string is an array of characters.The substring that is to be generated in this problem can be generated by deleting some characters of the string. And without changing the order of the string.Input: ‘abc’ Output: ab, ac, abcTo solve this problem, we will iterate the string and fix vowels and check for the next sequence. Let’s see an algorithm to find a solution −AlgorithmStep 1: Iterate ...
Read MorePrint all Subsequences of String which Start with Vowel and End with Consonant in C++
In this problem, we are given a string and we have to find the substring from the given string. The substring to be found should start with a vowel and end with constant character.A string is an array of characters.The substring that is to be generated in this problem can be generated by deleting some characters of the string. And without changing the order of the string.Input: ‘abc’ Output: ab, ac, abcTo solve this problem, we will iterate the string and fix vowels and check for the next sequence. Let’s see an algorithm to find a solution −AlgorithmStep 1: Iterate ...
Read MorePrint all paths from a given source to a destination in C++
In this problem we are given a directed graph and we have to print all paths from the source to the destination of the graph.Directed graph is a graph in with edges that are directed from vertex a to b.Let’s take an example to understand the problem Source = K destination = POutput:K -> T -> Y -> A -> P K -> T -> Y -> P K -> A -> PHere, we have found paths from K to P. We have traversed paths and printed all paths from K that direct us to P.To solve this problem, we will ...
Read MoreFill missing entries of a magic square in C++
Suppose we have one 3x3 matrix, whose diagonal elements are empty at first. We have to fill the diagonal such that the sum of row, column and the diagonal will be same. Suppose a matrix is like −036505470After filling, it will be −636555474Suppose the diagonal elements are x, y, z. The values will be −x = (M[2, 3] + M[3, 2])/ 2z = (M[1, 2] + M[2, 1])/ 2y = (x + z)/2Example#include using namespace std; void displayMatrix(int matrix[3][3]) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cout
Read MoreFinal cell position in the matrix in C++
Suppose we have a set of commands as a string, the string will have four different letters for four directions. U for up, D for down, L for left and R for right. We also have initial cell position (x, y). Find the final cell position of the object in the matrix after following the given commands. We will assume that the final cell position is present in the matrix. Suppose the command string is like “DDLRULL”, initial position is (3, 4). The final position is (1, 5).The approach is simple, count the number of up, down, left and right ...
Read More