Found 7197 Articles for C++

isfinite() function in C++

Sunidhi Bansal
Updated on 28-Feb-2020 05:48:43

391 Views

In this article we will be discussing the working, syntax and examples of isfinite() function in C++.isfinite() is an inbuilt function in C++ which comes under header file. isfinite() function used to check and return whether the given number is finite or not, a finite number is any floating number which is neither infinite nor NaN (Not a number).Syntaxbool isfinite(float n);orbool isfinite(double n);orbool isfinite(long double n);This function include only 1 parameter n which is the value we have to check for whether it's finite or not.Return valueThe function returns boolean value, 0(false) if the number is not finite and 1(true) ... Read More

fma() function in C++

Sunidhi Bansal
Updated on 28-Feb-2020 05:42:33

63 Views

Given the task is to show the working of fma() function in C++. In this article we will look into what parameters this function need and what results it will be returning.fma() is an inbuilt function of cmath header file, which accepts three parameters x, y and z and return the result x*y+z without losing the precision in any intermediate result.Syntaxfloat fma(float x, float y, float z);Ordouble fma(double x, double y, double z); Orlong double fma(long double x, long double y, long double z);Parametersx − The first element to be multiplied.y − The second element with which x is to ... Read More

deque_crend in C++ in STL

Sunidhi Bansal
Updated on 28-Feb-2020 05:29:25

144 Views

Given is the task to show the functionality of Deque crend( ) function in C++ STLWhat is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the ... Read More

deque_emplace in C++ in STL

Sunidhi Bansal
Updated on 28-Feb-2020 05:23:51

184 Views

Given is the task to show the functionality of Deque emplace( ) function in C++ STLWhat is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the ... Read More

Max Chunks To Make Sorted in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:26:16

450 Views

Suppose we gave an array arr that is a permutation of [0, 1, ..., arr.length - 1], we have to split the array into some number of "chunks" or partitions, and individually sort each partition. So after concatenating them, the result will be the sorted array. So if the array is like [1, 0, 2, 3, 4], then the output will be 4, as we can split into two partitions like [1, 0] and [2, 3, 4], but this can also be true that [1, 0], [2], [3], [4]. So this is the highest number of chunks possible, so output ... Read More

Partition Labels in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:23:37

399 Views

Suppose we have a string S of lowercase letters is given. We will partition this string into as many parts as possible so that each letter appears in at most one part, finally return a list of integers representing the size of these parts. So if the string is like “ababcbacadefegdehijhklij”, output is [9, 7, 8], because the partitions are “ababcbaca”, “defegde”, “hijhklij”. So this is a partition so that each letter occurs in at most one part. A partition like "ababcbacadefegde", "hijhklij" is not correct, because it splits S into less parts.To solve this, we will follow these steps ... Read More

Daily Temperatures in Python

Arnab Chakraborty
Updated on 29-Apr-2020 08:20:55

986 Views

Suppose we have a list of daily temperatures T, we have to return a list such that, for each day in the input, shows how many days we would have to wait until a warmer temperature. If there is no future day for which this is possible, store 0 instead. For example, if T = [73, 74, 75, 71, 69, 72, 76, 73], output will be [1, 1, 4, 2, 1, 1, 0, 0].To solve this, we will follow these steps −ans := an array of size same as T, and fill this with 0define one stack, and insert 0 ... Read More

Subarray Product Less Than K in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:17:39

357 Views

Suppose we have given an array of positive integers nums. We have to count and print the number of (contiguous) subarrays where the product of each the elements in the subarray is less than k. So if the input is like [10,5,2,6] and k := 100, then the output will be 8. So the subarrays will be [[10], [5], [2], [6], [10, 5], [5, 2], [2, 6] and [5, 2, 6]]To solve this, we will follow these steps −temp := 1, j := 0 and ans := 0for i in range 0 to size of the arraytemp := temp * nums[i]while temp >= k and j = k && j

Minimum ASCII Delete Sum for Two Strings in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:12:07

446 Views

Suppose we have two words w1 and w2, we have to find the lowest ASCII sum of deleted characters to make w1 and w2 the same, where in each step we can delete one character in either string. So if the input is like “sea” and “eat”, then the output will be 231, because we need to delete ‘s’ from w1, this will be “ea” and delete “t” from “eat” from w2. Then they are same. Deleting ‘t’ from “eat” adds 116 to the sum, and at the end, both strings are the same and 115 + 116 = 231 ... Read More

Insert into a Binary Search Tree in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:08:57

8K+ Views

Suppose we have a binary search tree. we have to write only one method, that performs the insertion operation with a node given as a parameter. We have to keep in mind that after the operation, the tree will remain BST also. So if the tree is like −if we insert 5, then the tree will be −To solve this, we will follow these steps −This method is recursive. this is called insert(), this takes a value v.if root is null, then create a node with given value v and make that as rootif value of root > v, thenleft ... Read More

Advertisements