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

228 Views
In C++, to print the odd-numbered levels of a binary tree, the levels are numbered from the root as Level 1. The odd-numbered levels are Level 1, Level 3, and so on. This program prints the nodes present at these odd levels. It uses level-order traversal to process the tree level by level and prints the nodes found at these levels. Algorithm to Print only Odd Numbered Levels of a Tree Following is the Algorithm to print odd numbered levels of a tree − Create a structure for tree nodes with data and pointers to left ... Read More

24K+ Views
In C++, there are two main ways to pass arguments to functions: pass by value and pass by reference. When you use pass by value, a copy of the variable is made, so the original variable doesn't change. With pass by reference, the function works with the original variable, so it can be changed directly. Each method is used based on what you want the function to do. We can pass arguments into a function in different ways. These different ways are − Call by Value Call by Reference ... Read More

955 Views
Single quotes in C++ are used to denote characters, not strings. When you use single quotes around multiple characters or strings, C++ compiler will treat it as a multi-character literal, which will be stored as an integer value, representing the combined ASCII values of those characters. In this article, we will learn all about single quotes in C++ and how they behave when used with multiple characters. Single Quotes in C++ In C++, single quotes are used to represent a single character. For example, 'a' is a character literal representing the english alphabet 'a'. For each character, C++ assigns a ... Read More

519 Views
When using std::getline after a formatted extraction (like std::cin >>), you might see an unexpected behavior, where std::getline is skipping the next input line. In this article, we will understand why this happens and how to handle it. Getline skipping input after formatted extraction The code below shows how getline() is skipping input after a formatted extraction: #include #include using namespace std; int main() { string name; string city; cin

872 Views
Binary Search Tree (BST) is a special binary tree in which the left subtree of a node contains only nodes with values less than the node's value, and the right subtree contains only nodes with values greater than the node's value. In this article, we will learn how to perform a right rotation on a BST node using C++. What is Right Rotation in BST? Right rotation is a type of tree rotation technique that is used to balance a binary search tree. In the right rotation around a node, the node is moved to the right in such ... Read More

592 Views
Binary Tree traversal is a process of visiting all the nodes in a certain order. In this article, we will learn how to perform postorder non-recursive traversal of a binary tree using two stacks in C++. What is Postorder Non-Recursive Traversal? Postorder traversal is a type of depth-first traversal where we first visit the left subtree, then the right subtree, and then the root node. In a non-recursive approach, we are not allowed to use recursive functions to track nodes for traversing the tree. Instead, we can use stack data structures to manually keep track of the nodes. This ... Read More

2K+ Views
A Binary Search Tree (BST) is a sorted binary tree in which each node follows two key properties: The right subtree of a node contains only keys greater than the node's key. The left subtree of a node contains only keys less than the node's key. Additionally, each node has at most two children. Tree Rotation Tree rotation is an operation that changes the structure without interfering with the order of the elements on a binary tree. It moves one node up in the tree and one node down. ... Read More

775 Views
Binary Tree traversal is a process of visiting all the nodes in a certain order. In this article, we will learn how to perform inorder non-recursive traversal of a binary tree using a stack in C++. What is Inorder Non-Recursive Traversal? Inorder traversal is a type of tree traversal, where we first visit the left subtree, then the root node, and then the right subtree. In a non-recursive approach, we are not allowed to use recursive functions to track nodes for traversing the tree. Instead, we can use an explicit stack data structure to track nodes and traverse through ... Read More

2K+ Views
A dictionary is a collection of key-value pairs where, keys are unique and used to identify corresponding values in the dictionary. In this article, we will learn how to perform dictionary operations such as insertion, search, and traversal using a binary search tree (BST) in C++. What is BST? A binary search tree (BST) is a tree data structure, where each node has at most two children and follows two rules: the left subtree contains keys less than the node’s key, and the right subtree contains keys greater than the node’s key. This structure is same as how a ... Read More

680 Views
A ternary tree is a type of tree data structure in which each node can have at most three children. In this article, we will learn how to implement a ternary tree in C++ using basic class structures and pointers. What is Ternary Tree? A ternary tree is a tree in which each node has up to three children, that is left, middle, and right. It is same as a binary tree, but with an extra child node for each node. Each node in a ternary tree stores a data value and pointers to its three child nodes. ... Read More