C++ Articles

Page 278 of 597

C++ Program to Find Size of the Largest Independent Set(LIS) in a Given a Binary Tree

Samual Sam
Samual Sam
Updated on 11-Mar-2026 210 Views

This is a C++ Program to Find Size of the Largest Independent Set (LIS) in a Given a Binary Tree.AlgorithmBegin.    Create a structure n to declare data d, a left child pointer l and a right child pointer r.    Call a function max() to return maximum between two integers. Create a function LIS() to return the    size of the largest independent set in a given binary tree.    Calculate size excluding the current node    int size_excl = LIS(root->l) + LIS(root->r)    Calculate size including the current node    int size_incl = 1;    if (root->l)   ...

Read More

Set vs Map in C++ STL

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 2K+ Views

Set is an abstract data type in which each element has to be unique because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, but it is possible to remove and add the modified value of that element.A Map is an associative container that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values.So, it is clear from above that, set contains the only key, and map contains a value with ...

Read More

Sorting in C++

George John
George John
Updated on 11-Mar-2026 2K+ Views

In this section we will see how to perform sorting algorithm in C++. A sorted array is an array in which each of the elements are sorted in some order such as numerical, alphabetical etc. There are many algorithms to sort a numerical array such as bubble sort, insertion sort, selection sort, merge sort, quick sort, heap sort etc. More details about sorting the array using selection sort are given below.The selection sort is a sorting method that yields a sorted array. It does so by repeatedly finding the smallest element in the array and interchanging it with the element ...

Read More

C++ Program for Inorder Tree Traversal without Recursion

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 726 Views

If a binary tree is traversed in-order, the left subtree is visited first, then the root and later the right sub-tree. The output the key in ascending order in in_order traversal. This is a C++ Program for Inorder Tree Traversal without Recursion.AlgorithmBegin      Function inOrder():       Declare a stack s.       Declare the current node as root.       While current node is not null and stack is not empty do          While current node is not null do             Push the current node on the ...

Read More

C++ Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree

Samual Sam
Samual Sam
Updated on 11-Mar-2026 281 Views

A binary tree is a tree data structure in which each node has at most two children, which are defined as left child and right child.AlgorithmBegin    function identical():        Take two nodes r1 and r2 as parameter.       If r1 and r2 is NULL then          Return true.       If r1 or r2 is NULL then          Return false.       Return (r1->d is equal to r2->d and          Call function Identical(r1->l, r2->l) and          Call functions Identical(r1->r, r2->r) ); ...

Read More

Precedence of postfix ++ and prefix ++ in C/C++

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 2K+ Views

Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)Example#include using namespace std; int main() {    char arr[] = "Hello World";    char *ptr = arr;    ++*ptr;    cout

Read More

C++ Program to Construct an Expression Tree for a Postfix Expression

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

An expression tree is basically a binary tree which is used to represent expressions. In expression tree, nodes correspond to the operator and each leaf node corresponds to the operand. This is a C++ program to construct an expression tree for a postfix Expression in inorder, preorder and postorder traversals.AlgorithmBegin    Function r() has a character variable as parameter.       If the characters are + or - or * or / then          Return will be -1       If the characters are from A to Z then          Return will ...

Read More

Complex numbers in C++

George John
George John
Updated on 11-Mar-2026 10K+ Views

In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example#include using namespace std; class complex {    int real, img;    public:       complex() {     ...

Read More

How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 421 Views

In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --.To solve this problem, we can solve them using binary adder logic. In that case we were designed half adder and full adder. These adders can add one bit binary numbers. By cascading multiple adders, we have can create circuit to add bigger numbers.In that adder, we have performed XOR operation among the numbers, then for the carry we were performing the ANDing logic. These features are implemented here to add two numbers.Example Code#include using namespace std; int add(int ...

Read More

What uses are there for “placement new” in C++?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 248 Views

In this section we will see what is the placement new operator in C++. This placement new is another variation of new operator. The normal new operator performs two things. It allocates memory, and then constructs an object in allocated memory.The new operator allocates memory in the heap section and constructs objects there. But for the placement new operator, it constructs object at the given address. To deallocate memory, we can use delete keyword if the memory is allocated using new operator. But for placement new there is no placement delete feature.So in a nutshell, placement new allows you to ...

Read More
Showing 2771–2780 of 5,961 articles
« Prev 1 276 277 278 279 280 597 Next »
Advertisements