Found 7347 Articles for C++

Inorder Traversal of a Threaded Binary Tree in C++

Arnab Chakraborty
Updated on 10-Aug-2020 08:46:00

4K+ Views

Here we will see the threaded binary tree data structure. We know that the binary tree nodes may have at most two children. But if they have only one children, or no children, the link part in the linked list representation remains null. Using threaded binary tree representation, we can reuse that empty links by making some threads.If one node has some vacant left or right child area, that will be used as thread. There are two types of threaded binary tree. The single threaded tree or fully threaded binary tree.For fully threaded binary tree, each node has five fields. ... Read More

Doubly Linked Circular Lists in C++

Arnab Chakraborty
Updated on 10-Aug-2020 08:33:43

1K+ Views

Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.In doubly linked list, the next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions.As per the above illustration, following are the important points to be considered.The last link's next points to the first link of the ... Read More

Multidimensional Arrays in C

Arnab Chakraborty
Updated on 10-Aug-2020 08:14:34

176 Views

Here we will see the multidimensional arrays. An array is basically a set of homogeneous data. They are placed into contiguous memory locations. In different cases we can see that arrays are not one dimensional. Sometimes we need to create an array in two-dimensional or multidimensional form.The multidimensional arrays can be represented by two different approaches. These are Row-Major approach, and another is Column-Major approach. Consider a two-dimensional array with r rows and c columns. The number of elements in the array is n = r * c. The elements at position A[i, j], where 0 ≤ i < r ... Read More

Sorted Arrays in C++

Arnab Chakraborty
Updated on 10-Aug-2020 08:08:12

491 Views

Here we will see some basic concepts of the sorted arrays. The arrays are homogeneous data structure to hold same kind of data in some consecutive memory locations. Sometimes we need to sort the elements to use them. Other than that we can make a sorted array. That will always be sorted.In this case we will see the algorithms for insert and delete into sorted array. If we insert some element in it, it will automatically be placed at sorted position. So we do not need to sort it again after insertion. When we delete, it will delete the element, ... Read More

Dequeue and Priority Queue in C++

Arnab Chakraborty
Updated on 10-Aug-2020 07:54:44

2K+ Views

As we know that the queue data structure is First in First Out data structure. The queue has some variations also. These are the Dequeue and the Priority Queue.The Dequeue is basically double ended queue. So there are two front and two rear pairs. One pair of front and rear pointer is used to describe the queue from left side, and another one is used to describe it from the right side. We can insert or delete elements from both side in this structure. Here we will see some C++ code using dequeue STL to understand its functionality.Example (Dequeue) Live Demo#include ... Read More

Circular Queue Data Structure in C++

Arnab Chakraborty
Updated on 10-Aug-2020 07:53:01

1K+ Views

A queue is an abstract data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e the element that is inserted first is also deleted first.Queue cane be one linear data structure. But it may create some problem if we implement queue using array. Sometimes by using some consecutive insert and delete operation, the front and rear position will change. In that moment, it will look like the queue has no space to insert elements into it. Even if there are some free spaces, that will not be used due to some logical problems. To overcome this ... Read More

Sum of the nodes of a Circular Linked List in C++

sudhir sharma
Updated on 06-Aug-2020 08:29:34

218 Views

In this problem, we are given a circular linked list. Our task is to create a program to find the sum of the nodes of a Circular Linked List.We simply need to add all the node values of the linked list.Some important definitions Linked List is a sequence of data structures, which are connected together via links.Circular Linked List is a variation of the Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.Now, let’s ... Read More

Sum of the natural numbers (up to N) whose modulo with K yield R in C++

sudhir sharma
Updated on 06-Aug-2020 08:26:42

214 Views

In this problem, we are given three numbers N, K and R. Our task is to create a program to find the Sum of the natural numbers (up to N) whose modulo with K yield R.We will add all the numbers less than N that satisfy the following condition, i%K == R.Let’s take an example to understand the problem, Input N = 14, K = 4, R = 1Output 28Explanation − All the numbers less than N, that given 1 as remainder when divided by 4 are 1, 5, 9, 13.To solve this problem, we will loop from R to N, and ... Read More

Sum of the multiples of two numbers below N in C++

sudhir sharma
Updated on 06-Aug-2020 08:25:22

262 Views

In this problem, we have given three integers M1, M2, and N. Our task is to create a program to find the sum of multiples of two numbers below N.Here, we will add all the elements below N which are multiples of either M1 or M2Let’s take an example to understand the problem, Input N = 13, M1 = 4, M2 = 6Output  20Explanation − Number that are multiples of 4 and 6 that are less than 13 are 4, 6, 8, 12.A simple solution to the problem is to be looping from 1 to N and adding all values that can ... Read More

Sum of the mirror image nodes of a complete binary tree in an inorder way in C++

sudhir sharma
Updated on 06-Aug-2020 08:24:23

101 Views

In this problem, we are given a complete binary tree. Our task is to create a program to find the sum of the mirror image nodes of a complete binary tree in an inorder way.Here, we have to find the inorder traversal of the left sun-tree, and then for each node, we will add the mirror image with it. This means if we are traversing the left leaf node, we will add the value of the right leaf node with it. As it is the mirror image node.Some important definitionsComplete binary tree is a binary tree where all levels have ... Read More

Advertisements