Get Middle Element of LinkedList in a Single Iteration

Aishwarya Naglot
Updated on 04-Aug-2025 15:50:14

233 Views

The java.util.LinkedList class represents a linked list in Java, specifically a doubly-linked list, i.e., we can traverse through the list either from the beginning or from the end, whichever is closer to the specified index. We can create and perform various operations on a linked list using the methods provided by this class. In this article, we will understand how to find the middle element of a LinkedList using Java. We will use the following ways to do so: Using a While Loop Using size() Method Using ... Read More

Call Method on 'this' Keyword from a Constructor in Java

Maruthi Krishna
Updated on 04-Aug-2025 13:32:14

6K+ Views

The “this" keyword in Java is used as a reference to the current object within an instance method or a constructor. Using this, you can refer to the members of a class, such as constructors, variables, and methods. Calling a Method using "this" From a Constructor Yes, as mentioned, we can call all the members of a class (methods, variables, and constructors) from instance methods or constructors. Example In the following Java program, the Student class contains two private variables, name and age, with setter methods and a parameterized constructor that accepts these two values. From the constructor, we are ... Read More

Absolute Difference of All Pairwise Consecutive Elements in an Array - C++

Revathi Satya Kondra
Updated on 01-Aug-2025 18:06:10

623 Views

An array in C++ is a data structure used to store multiple values of the same type in a contiguous block of memory. To know that how values shift from one index to the next, a common and practical technique is to compute the absolute difference between each pair of consecutive elements. Absolute Difference The absolute difference is the positive distance between two numbers, regardless of which one is larger. It is computed using the abs() function from the library. Absolute difference between a and b is denoted as |a - b|. For example, |7 - 3| = ... Read More

Best IDE for C++ on Linux

Akansha Kumari
Updated on 01-Aug-2025 17:51:02

632 Views

While developing softwares, the big projects become difficult to manage on mere text editors. So using an IDE makes it more smoother and productive. In this article we will discuss the popular IDE's for working with C++ programs on a Linux environment. We will compare the features of various IDEs and help you choose the best one for your needs. Best IDE's for C++ Programming Here is the list of best IDE's for C++ programming in Linux. Visual Studio Code (VS Code) Code::Blocks Eclipse ... Read More

C++ Program for Finding the Number Occurring Odd Number of Times

sudhir sharma
Updated on 01-Aug-2025 17:48:12

400 Views

In this article, we implement a C++ program to find the number that occurs an odd number of times in an array, using different approaches. We are given an array containing multiple elements, and our task is to identify the number that appears an odd number of times. For example, consider the array: [1, 2, 1, 3, 3, 2, 2]. In this case, the number 2 appears 3 times, which is odd. Example Scenarios Let's look at a few example scenarios to understand the problem: Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} ... Read More

Absolute Difference of Even and Odd Indexed Elements in an Array in C++

sudhir sharma
Updated on 01-Aug-2025 16:58:01

940 Views

An array in C++ is a collection of elements of the same data type stored in contiguous memory locations. Arrays provide a way to store multiple values using a single variable name, and each element can be accessed using an index starting from 0. Even and Odd Indexed Elements in an Array Each element in an array has an index. Indexes that are divisible by 2 (like 0, 2, 4, etc.) are known as even indexes, while indexes that are not divisible by 2 (like 1, 3, 5, etc.) are referred to as odd indexes. For example, in the ... Read More

C++ Program for Common Divisors of Two Numbers

Revathi Satya Kondra
Updated on 31-Jul-2025 18:17:56

2K+ Views

What are Common Divisors? The common divisors of two numbers are the numbers that are divisors of both. A number is said to divide another number if it leaves no remainder when divided. For example, 3 divides 12 since 12 / 3 = 4 (no remainder). But 5 does not divide 12 because 12 / 5 = 2 with a remainder of 2. Understanding with an Example Let’s take two numbers, 12 and 18. We list all the divisors of both numbers and identify the common ones. ... Read More

Find Maximum Fruit Count to Make Compote in C++

Farhan Muhamed
Updated on 31-Jul-2025 17:02:43

564 Views

In this article, we will explain maximum fruit count to make compote problem and implement a C++ program to solve it. The problem involves finding the maximum number of fruits that can be used to make a compote, given certain constraints. Let's break down the problem statement below. Maximum Fruit Count to Make Compote You are given a list of fruits, say a apples, b bananas, and c cherries, where a, b, and c are the counts of each type of fruit. Your task is to make a compote using these fruits such that the apples, bananas and cherries ... Read More

Compare Float and Double in C++

sudhir sharma
Updated on 31-Jul-2025 16:10:44

747 Views

In C++, floating-point numbers are used to represent decimal values. The most commonly used floating-point types are float and double. These data types differ in their size, precision, and use cases. Understanding how to use and compare them correctly is important for accurate computations. Understanding Float and Double Precision The float is a 32-bit single-precision floating-point type that can store approximately 7 decimal digits, while double is a 64-bit double-precision type that offers about 15 to 16 digits of precision. Due to these differences, double is generally preferred for higher accuracy in scientific and financial calculations. Example: Printing ... Read More

All Unique Triplets That Sum Up to a Given Value in C++

Manisha Chand
Updated on 31-Jul-2025 15:40:28

415 Views

Unique Triplets that Sum up to a Given Value In this article, we will discuss different approaches to find all the unique triplets that sum up to the given value. Before that, first understand the given problem. We have been given an integer array with N elements, along with a target value. Our task is to find unique or distinct triplets (i.e., three numbers) from an array, whose sum is the same as the target value. Let's take a scenario to understand the problem in a better way: Scenario 1 Input: arr ={1, 2, 3, 4, 5, 6, 7} ... Read More

1 2 3 4 5 ... 7805 Next
Advertisements