Found 7347 Articles for C++

Alternate sorting of Linked list in C++

sudhir sharma
Updated on 16-Oct-2019 07:46:07

149 Views

A linked list is a linear data structure that stores elements and also stores a pointer to the next data node.In this problem on the sorting of a linked list, the alternate sort means sorting in such a way that the 1st node contains data with the minimum value, the 2nd node contains data with maximum value, 3rd with the next minimum (second minimum value) and so on. This pattern of alternate maxima and minimas is created in alternate sorting of linked lists.Let’s take an example to understand the problem better −Input : 3 > 4 > 21 >67 > ... Read More

Alternate Odd and Even Nodes in a Singly Linked List in C++

sudhir sharma
Updated on 16-Oct-2019 07:39:21

268 Views

A single linked list is a linear data structure that contains two parts − one data and other pointers to the next element in the list.An alternate odd and even singly linked list is a linked list that has one node with even data and the other node with odd data members.In this problem, we have to rearrange the elements of a predefined singly linked list in either of the two ways which define the alternate odd and even singly linked list.Two ways are − the first element of the Linked list is even then the next element should be ... Read More

Alternate Lower Upper String Sort in C++

sudhir sharma
Updated on 16-Oct-2019 07:34:36

439 Views

A string is an array of characters. And this problem is to sort the elements of the string with alternate upper and lower case.Problem Description − Alternate lower upper string sort, is a problem in which we are provided an unordered string which contains mixed upper and lowercase characters and we need to sort this string in such a way that upper and lower case characters are placed in alternate positions but are in a sorted manner.Let’s take an example to understand the topic better, Input : aFegrAfStRzsV Output : AaFeRfSgVrstz Explanation : Upper case characters : A F R ... Read More

Alternate bits of two numbers to create a new number in C++

sudhir sharma
Updated on 16-Oct-2019 07:30:55

113 Views

In this problem, we need to generate a number by using alternate bits of two numbers. So, in this problem we will use the first bit from the second number, then second bit from first, the third bit again from the second number and forth from first and so on.From first, the third bit again from the second number and forth from first and so on.Lets take an example to understand the topic better, Input : n = 6 m = 10 Output : 2 Explanation : Bits representation of 6 = 0110 Bit representation of 10 = 1010 0 ... Read More

Almost Perfect Number in C++

sudhir sharma
Updated on 16-Oct-2019 07:26:27

140 Views

Almost Perfect Number also known the least deficient number or slightly defective number is a number in which the sum of all divisors ( adding 1 and the number itself ) should be equal to 2n-1.In this problem, we will define an algorithm to check whether a number is an almost a perfect number or not.Let's take an example to understand the concept better, Input : 16 Output : yes Explanation : Divisors of 16 are 1, 2, 4, 8, 16. Sum = 1 + 2 + 4 + 8 + 16 = 31 n = 16 ; 2n-1 = ... Read More

Allocate minimum number of pages in C++

sudhir sharma
Updated on 16-Oct-2019 07:18:39

349 Views

Allocate a minimum number of pages is a programming problem. Let's discuss this problem in detail and see what can be the solution to it.StatementYou are given the number of pages of n different books. Also, there are m students to whom the books are to be assigned. The books are arranged in ascending order of the number of pages. And every student can be assigned some consecutive books. The program should return the maximum number of pages read by a student which should be minimum.Let's take an example to understand this problem in a better way, Input : books[] ... Read More

Anonymous classes in C++

sudhir sharma
Updated on 16-Oct-2019 07:09:38

2K+ Views

Anonymous entity is anything that is defined without a name. A class with no name provided is known as an anonymous class in c++. An anonymous class is a special class with one basic property.As there is no name given to the class there is no constructor allocated to it, though a destructor is there for deallocating the memory block.The class cannot be used as an element of a function i.e. you cannot pass it as an argument or cannot accept values return from the function.The syntax for defining an anonymous class in c++class {    //data members    // ... Read More

Alternate Fibonacci Numbers in C++

sudhir sharma
Updated on 16-Oct-2019 07:00:02

513 Views

Fibonacci Number is defined as a sequence of numbers that starts with two fixed numbers, generally, o, 1 or 1, 1 and the successive elements of the sequence are the sums of the previous two numbers of the sequence.For example, Fibonacci series till 8 elements is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.Now, let's generalize this series. Here, the value of the nth term is equal to the sum of (n-1)th and (n-2)th term. So, let's get the mathematical derivation of the formula for the nth term of the Fibonacci series.Tn = Tn-1 + Tn-2Using ... Read More

Aliquot Sequence in C++

sudhir sharma
Updated on 16-Oct-2019 06:56:44

241 Views

Aliquot sequence is a special sequence of numbers. The sequence starts from the number itself and the next number of the sequence is the sum of the proper divisors of the previous terms.Let’s take an example of the sequence to learn the concept better −Input : 8 Output : 8 7 1 0 Explanation :    Proper divisors of 8 are 4, 2, 1. The sum is 7    Proper divisors of 7 are 1. The sum is 1    Proper divisors of 1 are 0. The sum is 0Perfect number is the number that has the aliquot sequence of ... Read More

Alignof operator in C++

sudhir sharma
Updated on 16-Oct-2019 06:51:16

538 Views

Operator is a symbol which is used to indicate the compiler to perform some operation in programming language.alignof operator is the operator that returns the alignment that is to be applied to the given type of variable. The returned value is in bytes.Syntaxvar align = alignof(tpye)Explanationalignof − the operator is used to return the alignment of the inputted data.parameter type − the data type whose alignment is to be returned.return value − The value in bytes that is be used as alignment for the given data type.ExampleThe program to return the values for align of basic data types. Live Demo#include ... Read More

Advertisements