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

1K+ Views
What is a virtual function?A virtual function is a method that does not have a definition when defined in the base class. This method is left black in the parent class and it is redefined in the child class.What is an abstract class?An abstract class is a class that has abstract members or at least one pure virtual function in its definition. An abstract class can never be instanced (creating an object). It can only be inherited and the methods could be overwritten.Can there be any virtual Destructors?Yes, These are legal in C++, but these are destructors are for base ... Read More

9K+ Views
As we know in programming execution of code is done line by line. Now in order to alter this flow Java provides two statements break and continue which are mainly used to skip some specific code at specific lines. Difference Table Following are the important differences between continue and break − Sr. No. Key ... Read More

8K+ Views
Both C and C++ are middle-level programming languages that are used for developing system software as well as application software. C is a procedural programming language which have low-level memory access and minimal runtime; therefore, it is used for writing operating systems, embedded systems, and system-level programs. whereas C++ is just an extension of the C language, which is both a procedural programming language and object-oriented. Therefore, having extra features that make it suitable for game development, GUI applications, and high-performance software. C Programming Language C is a general-purpose, procedural programming language, which was developed by Dennis M. Ritchie at ... Read More

156 Views
Given a binary tree, we have to print its leaf nodes and then we have to remove those leaf nodes and then repeat till there are no nodes left in the tree.ExampleSo the output of the problem should be −6 7 9 13 14 3 4 2 1ApproachWe have adopted an approach where we are applying DFS.For applying a temporary value zero is assigned to every value and then assign all the nodes with the value maximum(value of both child)+1.AlgorithmSTART STEP 1-> DEFINE A struct Node WITH DATA MEMBERS data, order, *left, *right STEP 2-> DEFINE A struct Node* ... Read More

474 Views
We are given with a binary tree of distinct nodes and two nodes of the binary tree whose path in the binary tree we want to print.For Example − We want to print the path between node 140 to 211 so its output should be like −Output: 140->3->10->211The idea is to find paths form root nodes to the two nodes and store them in two separate vectors or arrays say path1 and path2.Now, there arise two different cases −If the two nodes are in different subtrees of root nodes − When the two nodes are in different subtrees like one ... Read More

239 Views
Given the binary tree the program must find out the shortest path from the root to leaf amongst many given paths.Since we traverse the tree from left to right, so if there are multiple shortest paths from the root to leaf than the program will print the first traversed the shortest path on the left side of a tree.We can use a queue that will traverse each level using Level order traversal and the path with the least number of levels will be printed as it will be the shortest path from the root to leafIn the above tree, multiple ... Read More

247 Views
Given the binary tree the program must find out the multiple paths from the root to a leaf which means all the paths should be printed but the challenge is to without using recursion.We will traverse the tree iteratively as the constraint is to do it without recursion. So to achieve this we can use an STL map that will store the root element and whenever the leaf node is identified through level order traversal it will print the path from root to leaf as there is a map pointer which is pointing to a root node.In the above tree, ... Read More

160 Views
Given the binary tree, the program must print the nodes at odd levels of a tree and the levels of a binary tree start from 1 to n.As nothing is mentioned one of the two approaches can be implemented i.e. recursion or iteration.Since we are using a recursive approach, the program will make a recursive call to a function that will be fetching the nodes at odd levels and returning them.In the above binary tree −Nodes at level 1: 10 Nodes at level 2: 3 and 211 Nodes at level 3: 140, 162, 100 and 146So, the nodes at level ... Read More

267 Views
Given the binary tree, the task is to print the level associated with every key stored in a node starting from 1 to nIn the above tree, nodes are −10 at level 1 3 and 211 at level 2 140, 162, 100 and 146 at level 3Given the key the program must print the level of that particular key.ExampleInput: 10 3 211 140 162 100 146 Output: level of 10 is 1 Level of 3 is 2 Level of 211 is 2 Level of 140 is 3 Level of 162 is 3 Level of ... Read More

174 Views
Given the binary tree, the function will generate the binary values of the keys stored in the nodes and then return the number of set bits(1) in that binary equivalent.ExampleBinary tree having keys as: 10 3 211 140 162 100 and 146KeyBinary equivalentSet bits(output)101010230011221111010011514010001100316210100010310011001003146100100103Here we are using the function __builtin_popcountThe function prototype is as follows −int __builtin_popcount(unsigned int)It returns the numbers of set bits in an integer i.e. the number of ones in the binary representation of the integer.AlgorithmSTART Step 1 -> create a structure of a node as struct Node struct node *left, *right ... Read More