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

290 Views
In this tutorial, we will be discussing a program to convert a number into its negative base representation.For this we will be provided with a number and the corresponding negative base. Our task is to convert the given number into its negative base equivalent. We are allowing only values between -2 and -10 for negative base values.Example Live Demo#include using namespace std; //converting integer into string string convert_str(int n){ string str; stringstream ss; ss > str; return str; } //converting n to negative base string convert_nb(int n, int negBase){ //negative base equivalent for zero is ... Read More

226 Views
In this tutorial, we will be discussing a program to convert a normal binary search tree to balanced binary search tree.For this we will be provided with a skewed binary search tree either left or right. Our task is to convert it into a balanced binary search tree following a certain set of rules.Example Live Demo#include using namespace std; //node structure of tree struct Node{ int data; Node* left, *right; }; //traversing tree and storing node pointers //in vector nodes void store_nodes(Node* root, vector &nodes){ if (root==NULL) return; store_nodes(root->left, nodes); nodes.push_back(root); ... Read More

163 Views
In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a different approach. We will be traversing the binary tree in reverse inorder way. Along with we will be creating new nodes and moving ... Read More

219 Views
In this tutorial, we will be discussing a program to convert a binary tree to a doubly linked list.For this we will be provided with a binary tree. Our task is to convert it into a doubly linked list such that the left and right pointers become the previous and next pointers. Also the sequential order of the doubly linked list must be equal to the inorder traversal of the binary tree.For this we are having a very straight forward approach. We will be traversing the binary tree in in order way making the nodes of the doubly linked list ... Read More

156 Views
In this tutorial, we will be discussing a program to convert a given Binary tree to a tree that holds Logical AND property.For this we will be provided with a binary tree. Our task is to convert it into a tree that holds the logical AND property means that a node has a value of the AND operation of its children nodes. Note that every node can have a value either zero or one.Example Live Demo#include using namespace std; //node structure of binary tree struct Node{ int data; struct Node* left; struct Node* right; }; //creation of a ... Read More

376 Views
strncmp() and strcmp compares two strings using ASCII character comparison. strncmp takes one additional parameter as number to characters upto which a string is to be compared. It is very useful as if a string is not valid, then strcmp will not be able to complete its operation. strcmp searches for end character ('/0') at string end to finish its operation. strncmp uses no. of characters to end its operation and thus is safe.Example#include int main() { char str1[] = "TutorialsPoint"; char str2[] = "Tutorials"; // Compare strings with strncmp() int result1 = strncmp(str1, str2, ... Read More

956 Views
CIn C programming language, if a function signature is not having any parameters then it can take multiple arguments as input but the same is not true with C++. The compilation will fail if arguments are passed to such a function in C++. This is reason int main() and int main(void) are same in C, but int main(void) is better approach, which restricts the user to pass multiple arguments to main function.Example (C) Live Demo#include int main() { static int counter = 3; if (--counter){ printf("%d ", counter); main(5); } }Output2 ... Read More

391 Views
Suppose we have one level order traversal. From this traversal. we have to generate the tree So if the traversal is like [7, 4, 12, 3, 6, 8, 1, 5, 10], then the tree will be like −To solve this, we will use recursive approach. The first element will be the root. The second element will be the left child, and third element will be right child (If the condition of BST satisfies), this property will be satisfied for all elements. So we will follow these steps −At first we have to take the first element of the array, and ... Read More

219 Views
Suppose we have one pre order traversal. From this traversal. we have to generate the tree So if the traversal is like [10, 5, 1, 7, 40, 50], then the tree will be like −To solve this, we will follow these steps −Create empty stackMake the first value as root, and push it into stack.Now keep pooping while the stack is not empty and the next value is greater than stack top element, make this as right child of the last popped node. Now push the new node to the stack.When the next value is less than the top element, ... Read More

179 Views
Suppose we have one pre order traversal. From this traversal. we have to generate the tree So if the traversal is like [10, 5, 1, 7, 40, 50], then the tree will be like −To solve this, we will use this trick. The trick is to set a range {min… max} for each node. At first we will initialize the range as {INT_MIN… INT_MAX}. The first node will definitely be in range, so after that we will create root node. To construct the left subtree, set the range as {INT_MIN… root->data}. If a values is in the range {INT_MIN… root->data}, ... Read More