Server Side Programming Articles - Page 1644 of 2646

Find distance between two nodes of a Binary Tree in C++ Program

Ayush Gupta
Updated on 09-Oct-2020 09:14:45

334 Views

In this problem, we are given a binary tree and two nodes. Our task is to create a program to Find distance between two nodes of a Binary Tree.Problem DescriptionWe need to find the distance between two nodes which is the minimum number of edges that will be traversed when we go from one node to another node.Let’s take an example to understand the problem, Input: binary treeNode1 = 3 ,Node2 = 5Output: 3ExplanationThe path from node 3 to node 5 is 3 -> 1 -> 2 -> 5. There are 3 edges traversed that make distance 3.Solution ApproachA simple ... Read More

Queries to add, remove and return the difference of maximum and minimum in C++

Ayush Gupta
Updated on 09-Oct-2020 08:50:07

152 Views

In this problem, we are given Q queries. These are of three types, they are −Query 1: Add number N to the list.Query 2: Remove number N to the list.Query 3: Return the difference of minimum and maximum element of the list.Our task is to create a program to solve queries to add, remove, and return the difference of maximum and minimum in C++.Problem DescriptionWe will be given a Q number of queries that we will be performing on the list. There are 3 types of queries to add, remove, and find the difference of maximum and minimum element of ... Read More

Different methods to copy in C++ STL - std::copy(), copy_n(), copy_if(), copy_backwards()

Sunidhi Bansal
Updated on 14-Aug-2020 08:43:35

497 Views

As the method name suggests copy() method is used to copy the data through various methods available in C++ STL. All the methods differ in functionalities and the parameters. These methods are available in header file. Let’s discuss each method and their functionalities.Copy(start_i1, end_i1, start_i2)This method is used to copy the data from one iterator to another iterator within specified range where both the start and end elements of an iterator are inclusive. It takes three types of arguments i.e. −Start_i1 − It will point to the initial element of the iterator, let’s say, i_1 from where the element ... Read More

Different ways to declare variable as constant in C and C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:40:57

960 Views

There are multiple ways of declaring constants in C and C++. First of all, we need to understand what constant is.What is a Constant?Constant means which can’t be changed. In terms of programming, constants are the fixed values that are assigned to the variables such that they can’t be altered by any other variable or component during the execution of a program. Constants can be of any data type. They are used in the programming for defining the non-changing component of a program. There are some data or variables which have fixed value like Pi have fixed float value as ... Read More

Upper bound and Lower bound for non increasing vector in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:31:50

4K+ Views

In this article we are going to discuss the vector::upper_bound() and vector::lower_bound() for an array sorted in non-increasing order in C++ STL.Vectors are similar to the dynamic arrays; they have the ability to modify its size itself whenever a value is inserted into or removed from the container where we are storing the value.In a Vector, lower bound returns an iterator pointing to the first element in the range that does not compare the given value. Upper Bound returns an iterator pointing element in the range that smaller than given value.Input 30 30 30 20 20 20 10 10Output Lower bound of ... Read More

map count( ) function in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:29:37

5K+ Views

In this article we will be discussing the working, syntax and examples of map::empty() function in C++ STL.What is Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination on key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in map container is accessed by its unique keys.What is map::count()?The map::count( ) is a function which comes under header file. This function counts the elements with specific key, it returns 1 if ... Read More

Sin( ) function for complex number in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:27:16

230 Views

We are given with the task to find the working of sin() function for complex number. The sin( ) function for complex numbers are present in the complex header file which means for calculating the value of sin() we need to add the complex header file in the code. In mathematics this function is used to calculate the value of sin having complex numbers.SyntaxSyntax for sin() function is −sin(z);Parameterparameter z can be any complex number and this parameter is defined in the definition of sin() function which makes this parameter mandatory.Return typeThis function returns the complex value of sin( ) ... Read More

Sinh( ) function for complex number in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:25:45

265 Views

We are given with the task to find the working of sin() function for complex number. The sin( ) function for complex numbers are present in the complex header file which means for calculating the value of sin() we need to add the complex header file in the code. This function is used to calculate the complex hyperbolic sine of complex number.Syntaxtemplate complex Sinh(const complex& x);Parameterparameter z can be any complex number and this parameter is defined in the definition of sin() function which makes this parameter mandatory.Return typeThis function returns the complex value of sin( ) as it contains ... Read More

map max_size() in C++ STL

Sunidhi Bansal
Updated on 14-Aug-2020 08:24:33

1K+ Views

In this article we will be discussing the working, syntax and examples of map::max_size() function in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map::max_size()?map::max_size() function is an inbuilt function in C++ STL, which is defined in header file. max_size() is used to return ... Read More

map::operator[] in C++ STL Program

Sunidhi Bansal
Updated on 14-Aug-2020 08:23:02

487 Views

In this article we will be discussing the working, syntax and example of map equal ‘[]’ operator in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map equal to ‘[]’ operator?map::operator[] is a reference operator. This operator is used to access the element in the ... Read More

Advertisements