In this article, we will show you the difference between C/C++ pointers and Java references. C/C++ use pointers to manually control how memory is used and accessed. Java, on the other hand, does not support pointers and uses references instead, which manage memory automatically. Pointer in C/C++ A pointer is a variable that holds the address of another variable in memory. It gives you direct access to that memory, which is powerful but can lead to errors if not used carefully. Syntax Here's the syntax where we declare a pointer with an asterisk(*) ... Read More
In this article, we'll show you how to write a C++ program to find the largest element in an array. An array is a collection of values that share the same data type. Our task is to go through all the elements stored in the array and find the one with the highest value. For example, consider the following arrays: //Example 1 int arr[] = {11, 13, 21, 45, 8}; Here, the largest element is 45. //Example 2 int arr[] = {1, 9, 2, 5, 7}; In this case, the largest element is ... Read More
The bitwise XOR is a binary operation in which we compare two binary numbers bit by bit and return the value "1" if the bits are not same, and 0 if they are the same. The XOR(exclusive OR) operation follows the below rules - A B A ⊕ B ... Read More
A list is a built-in Python data structure that is used to store an ordered collection of items of different data types. It often occurs that lists contain duplicate values, i.e., the same element repeating multiple times, which causes data inaccuracies. In this article, we will discuss the approaches that can be used to remove the repeated elements from a list. Using set() Using List Comprehension Using a For Loop Using Dictionary fromkeys() Using set() Function The set() function accepts an iterable ... Read More
The Linear Congruential Generator (LCG) is a very simple technique to generate a sequence of numbers that looks like random numbers but is actually determined. It is one of the reasons to call it a pseudo-random number. The Linear Congruential Generator (LCG) technique generates a random number based on the previous number and uses a linear recurrence to generate the sequence of random numbers. In this article, we have set an initial value of Xn and defined the value of the constants. Our task is to generate pseudo-random numbers using the linear congruential generator in C++. Formula of Linear ... Read More
To sort less than 100 numbers in O(N) complexity, we can use the counting sort technique. The counting sort is a stable and non-comparison-based sorting technique, that is used to sort the objects according to the keys that are small integers. It counts the number of keys whose key values are same. It works by counting the occurrences of elements in the array. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity. In this article, we have an unsorted array containing twelve elements. Our task is to sort ... Read More
The merge sort technique is based on the divide-and-conquer technique. We divide the whole data set into smaller parts and merge them into a larger piece in sorted order. It is also very effective for worst cases because this algorithm has lower time complexity for worst cases too. A linked list can be sorted using merge sort very efficiently. For the linked list, the merging task is very simple. We can simply update the links to merge them. In this article, we have an unsorted linked list. Our task is to sort the given unsorted list using the merge ... Read More
Counting sort is a stable and non-comparison-based sorting technique, that is used to sort the objects according to the keys that are small integers. It counts the number of keys whose key values are same. It works by counting the occurrences of elements in the array. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity. In this article, we have an unsorted array. Our task is to implement the counting sort algorithm to sort the given unsorted array in C++. Example Here is an example of ... Read More
In this article, we will learn to select one item at a time from a JCheckBox in Java. When creating Java Swing applications, you might have situations where you need checkboxes to behave like radio buttons, such that a box can be checked singly at any given time. JCheckBox A JCheckBox can extend JToggleButton, and it can be a small box that is either checked or unchecked. When we click on a JCheckBox, it changes from checked to unchecked or vice versa automatically. Syntax The following is the syntax for JCheckBox initialization: JCheckBox checkBox = new JCheckBox("Option"); A JCheckBox can ... Read More
In this article, we will learn to set the background color of a JPanel in Java. When designing GUIs in Swing, changing the background color of panels is important for creating visually appealing applications. What is a JPanel? A JPanel is a container, and it is an invisible component in Java. The FlowLayout is a default layout for a JPanel. We can add most of the components, like buttons, text fields, labels, tables, lists, trees, etc., into a JPanel. Syntax The following is the syntax for JPanel initialization: JPanel panel = new JPanel(); Methods The important methods of JPanel are: ... Read More