Found 7197 Articles for C++

Alternative Sorting in C++

sudhir sharma
Updated on 16-Oct-2019 07:50:14

791 Views

Sorting the elements of an integer array in such a way that the first element is the maximum of the array and the second element of the sorted array is the minimum, the third one is the second minimum, the fourth one is the second maximum of the array and goes on.Let’s take an example to understand the concept better, Input : 4 1 8 2 9 3 7 Output : 9 1 8 2 7 3 4 Explanation : The elements in a sorted way is 1 2 3 4 7 8 9. Now, let’s create it in ... Read More

Alternate sorting of Linked list in C++

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

334 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++

Nishu Kumari
Updated on 29-Jul-2025 12:57:44

358 Views

Given a singly linked list, we need to rearrange its nodes so that even and odd numbers come one after the other alternatively. If the list starts with an even number, the next should be odd, then even, and so on. Similarly, if it begins with an odd number, the next should be even, then odd, and so on. Let's look at some example scenarios to understand the concept better. Scenario 1 Input: 45 -> 21 -> 2 -> 213 -> 3 -> 34 -> 78 -> 12 Output: 45 -> 2 -> 21 -> 34 -> 213 -> 78 ... Read More

Alternate Lower Upper String Sort in C++

Nishu Kumari
Updated on 29-Jul-2025 14:28:24

609 Views

We are given a string that contains both lowercase and uppercase characters, and we have to sort them in an alternate way, meaning one lowercase letter, then one uppercase letter, then again a lowercase letter, and so on, all in sorted order within their cases. Let's understand this with a few example scenarios. Scenario 1 Input: "aFegrAfStRzsV" Output: "AagfRsSeTvz" Explanation: Sorted uppercase letters: A, F, R, S, T, V Sorted lowercase letters: a, e, f, g, r, s, z We place one uppercase letter, then one lowercase letter, starting with an uppercase. We repeat this until all letters ... Read More

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

Nishu Kumari
Updated on 28-Jul-2025 19:26:34

216 Views

Here, we are given two numbers, and we have to create a new number by combining their bits in an alternating way. We take the first bit from the second number, the second bit from the first number, the third bit from the second again, and so on. We start from the least significant bit and continue until all bits from both numbers are used. Let's look at a few example scenarios to understand the problem clearly: Scenario 1: Input: First_number = 8, Second_number = 9 Output: 9 Explanation: Binary of 8 = 1000, Binary of 9 = ... Read More

Almost Perfect Number in C++

Manisha Chand
Updated on 31-Jul-2025 15:23:45

243 Views

Almost Perfect Number in C++ Almost Perfect Number is a positive integer n for which the sum of all its positive proper divisors (excluding the number itself ) is equal to n-1. (i.e., one less than the number n). It is also known as the least deficient number or slightly defective number. A positive proper divisor is a divisor of a number, excluding the number itself. For example, for n = 6; 1, 2, 3 are positive proper divisors but 6 itself is not. In Mathematics, we say A number n is almost perfect if: σ(n)-n = n-1 by ... Read More

Allocate minimum number of pages in C++

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

488 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

Alternate Fibonacci Numbers in C++

Nishu Kumari
Updated on 04-Aug-2025 16:24:15

717 Views

The Fibonacci sequence starts from 0 and 1, and each number is the sum of the previous two. In this problem, we are given a number n, and we need to print the first n numbers from the Fibonacci series, but only the numbers at alternate positions (like 0th, 2nd, 4th, and so on). Let's look at some example scenarios to understand it clearly: Scenario 1 Input: n = 7 Output: 0 1 3 8 Explanation: The first 7 Fibonacci numbers are 0 1 1 2 3 5 8. If we pick alternate numbers (index 0, 2, ... Read More

Alignof operator in C++

Akansha Kumari
Updated on 22-Aug-2025 15:22:29

776 Views

C++ alignof() Operator The alignof operator is the operator that returns the memory alignment for a given variable type. This alignment tells how the data is arranged and accessed in memory. It returns the value in bytes and is the part of the header file in C++. which is mainly used for low-level programming like memory management or hardware requirements. Syntax Here is the following syntax of alignof operator, which returns memory alignment required for a given data type in bytes: alignof(data_type) Example Demonstrating Usage of alignof() Operator Here is the following example code of using alignof() operator ... Read More

Virtual Copy Constructor in C++

sudhir sharma
Updated on 16-Oct-2019 06:32:23

7K+ Views

Before digging deep into the topics lets brush up all the related terms.A copy constructor is a special type of constructor that is used to create an object that is an exact copy of the object that is passed.A virtual function is a member function that is declared in the parent class and is redefined ( overridden) in a child class that inherits the parent class.With the use of a virtual copy constructor, the programmer will be able to create an object without knowing the exact data type of the object.In C++ programming language, copy Constructor is used to creating ... Read More

Advertisements