
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++

2K+ Views
AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.This is a C++ program to check if a given Binary Tree is an AVL Tree or not.AlgorithmBegin function AVL() returns true if the given tree is AVL otherwise false. if(root == NULL) return 1 leftheight = height(root->left) rightheight = height(root->right) if(abs(leftheight-rightheight) left) && AVL(root->right)) return 1 return 0 EndExample#include using namespace std; class nod { //node declaration public: int data; ... Read More

1K+ Views
This is a C++ program to convert string to char array in C++. This can be done in multiple different waysType1AlgorithmBegin Assign a string value to a char array variable m. Define and string variable str For i = 0 to sizeof(m) Copy character by character from m to str. Print character by character from str. EndExample#include #include using namespace std; int main() { char m[]="Tutorialspoint"; string str; int i; for(i=0;i

516 Views
If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reachability matrix is called transitive closure of a graph. Warshall algorithm is commonly used to find the Transitive Closure of a Given Graph G. Here is a C++ program to implement this algorithm.AlgorithmBegin 1. Take maximum number of nodes as input. 2. For Label the nodes as a, b, c….. 3. To check if there any edge ... Read More

211 Views
A bipartite graph is a graph in which if the graph coloring is possible using two colors only i.e.; vertices in a set are colored with the same color. This is a C++ program to check whether a graph bipartite or not using DFS.AlgorithmBegin An array color[] is used to stores 0 or 1 for every node which denotes opposite colors. Call function DFS from any node. If the node w has not been visited previously, then assign ! color[v] to color[w] and call DFS again to visit nodes connected to w. If ... Read More

1K+ Views
In this program a random graph is generated for random vertices and edges. The time complexity of this program is O(v * e). Where v is the number of vertices and e is the number of edges.AlgorithmBegin Develop a function GenRandomGraphs(), with ‘e’ as the number of edges and ‘v’ as the number of vertexes, in the argument list. Assign random values to the number of vertex and edges of the graph, using rand() function. Print the connections of each vertex, irrespective of the direction. ... Read More

203 Views
Here is a C++ Program to get all the unique factorization of a given integer such that addition of a partition results an integer. In this program, a positive integer n is given, and we shall generate all possible unique ways to represent n as sum of positive integers. Algorithm to Perform Unique Factorization Below is the algorithm to perform the unique factorization of a given number: Begin function displayAllUniqueParts(int m): 1) Set Index of last element k in a partition to 0 ... Read More

3K+ Views
Nowadays the compiler comes with default 64-bit version. Sometimes we need to compile and execute a code into some 32bit system. In that time, we have to use this feature.At first, we have to check the current target version of the gcc compiler. To check this, we have to type this command.gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........Here it is showing that Target is x86_64. So we are using the 64-bit version of gcc. Now to use the 32-bit system, we have to write the following command.gcc –m32 program_name.cSometimes this command may generate ... Read More

179 Views
In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More

1K+ Views
Sometimes we need variable number of inputs in our program. In this program we will see how to use cin to take variable number of inputs.The simple solution is run a loop, and when one specific value is pressed, it stops. The another idea is using the cin >> input. This will return false when value is non-numeric.Example#include using namespace std; main() { int input; int n = 0; cout > input) n++; cout

220 Views
C++ fdim() Function The fdim() function returns the positive difference between two floating-point values. For example, if we have two arguments, a and b, respectively, then it will return a-b if a > b, else it will return 0. This function is defined under or header files and supports float, double, and long double overloads. Syntax Here is the following syntax for fdim() function in C++. In the following syntax, data_type defines the type of data it will take as input and return. data_type fdim(data_type value_1, data_type value_2); Parameters This method accepts two parameters of floating type (i.e., can ... Read More