Programming Articles - Page 431 of 3363

Java Program to Reverse a List

Rudradev Das
Updated on 14-Jun-2024 15:35:05

20K+ Views

What is a Reverse List? Reverse a list is an operation of swapping or interchanging the elements position into a particular list. While you are writing a code in Java, you can easily reverse the order of a certain flow. It is a conventional way of any programming language in computer science. The reverse () method is a collection of class which reverses the position of first element to last element. Last element will earn the first position itself after the termination of the process. A list is an interface where the class method is denoted as a signature with ... Read More

Java Program To Reverse A Linked List Without Manipulating Its Pointers

Rudradev Das
Updated on 31-Mar-2023 14:36:14

2K+ Views

Linked List and Pointers In Java Linked list is liner data structure in Java environment, which use to store the elements in an adjacent manner. A linked list contains with some addresses and pointers which are used to create a link between the elements present in a list. There are two types of elements present in a linked list. Those are - data element and address element. The value of an element indicated by the data part where the address part helps to create a link between the elements aka node. In Java there is an another concept of ... Read More

Java Program to Return the Largest Element in a List

Rudradev Das
Updated on 31-Mar-2023 14:31:37

4K+ Views

We can use an array loop to return back the largest element from a list. Primarily this method, known as the comparison model. The maximum number present here in a certain list will be compared with the all elements present in that particular list. The process considers “n” as a number of inputs which will store as data value in an array. After that the program will display the largest element on the output console after refining the loop. In this article today; we will help you to understand and write some Java code by which you can find the ... Read More

Java Program to return the elements at the odd position in a list

Shriansh Kumar
Updated on 01-Aug-2024 11:43:36

950 Views

What is the Odd Position in a List? In Java, a List does not have predefined odd and even positions. However, if one considers the first position as index 0, then an odd position in the given List would be any index that is not divisible by 2. To determine if a position is odd, use the modulo operator (%).   How to Find Elements at Odd Position in a List? Below approaches are followed to find out the elements at the odd position in a list − By dividing index with 2 ... Read More

Modelling the Rankine Cycle in Python

Dr Pankaj Dumka
Updated on 30-Mar-2023 10:51:46

2K+ Views

Rankine cycle is the heart of any thermal power plant. A basic Rankine cycle has four processes, viz. reversible adiabatic work interactions in turbine and pump and isobaric heat interactions in boiler and condenser. A schematic of a thermal power plant is shown in the figure given below. To increase the efficiency of a Rankine cycle Regeneration has been used i.e. bleeding steam to turbine and mixing it with feed water in feed water heater. Different processes in the cycle have to be modelled with the help of data from stream tables. Therefore, it becomes very essential to have ... Read More

How to Access Index in Python’s tuple for Loop?

Shashank Dharasurkar
Updated on 28-Mar-2023 18:10:50

2K+ Views

When it comes to working with data sequences in Python, tuples are one of the excellent choices due to their immutability and efficiency. Fortunately, Python provides several built-in functions to simplify and speed up working with tuples, especially when you need to access the index of each element in a for-loop. This article will explore two approaches to accessing the index in a tuple for loop: the range() function and the enumerate() function. What is a Tuple in Python? Tuples in Python are a set of immutable elements separated by a comma. For example, consider the following tuple definition − ... Read More

How To Access Different Rows Of A Multidimensional Numpy Array?

Shashank Dharasurkar
Updated on 28-Mar-2023 18:04:14

2K+ Views

NumPy Multidimensional Arrays As the name suggests, Multidimensional Arrays are a technique that can be described as a way of defining and storing data in a format that has more than two dimensions (2D). Python allows the implementation of Multidimensional Arrays by nesting a list function inside another list function. Here are some examples on how we can create single and multidimensional arrays in Python using Numpy. Single Dimensional Array Example import numpy as np simple_arr = np.array([0, 1, 2, 3, 4]) print(simple_arr ) Output [0 1 2 3 4] Algorithm Import the NumPy library Use ... Read More

Haskell Program to Convert String value to byte Value

Akhil Sharma
Updated on 28-Mar-2023 15:21:13

403 Views

In Haskell, we will convert String Value to Byte value by using ord , B.pack and fromNum functions. In the first example, we are going to use (stringToBytes = map ord ) function and in the second example, we are going to call (stringToBytes = B.pack) function. And in the third example, we are going to use (byteList = map fromEnum str) function. Algorithm Step 1 − The Data.Char module is imported. Step 2 − The stringToBytes function is defined using ord function as, Step 3 − The program execution will be started from main function. The main() function ... Read More

Haskell Program to Convert Set of String to Array of String

Akhil Sharma
Updated on 28-Mar-2023 15:00:44

295 Views

In Haskell, We can use listArray and toList functions as well as list comprehension to convert set of string to array of string. In the first example, we are going to use (setToArray set = listArray (1, Set.size set) (Set.toList set)) function and in the second example, we are going to call (setToArray set = listArray (1, Set.size set) (toList set)) function directly from the main function. And in the third example, we are going to use (setToArray set = array (1, Set.size set) [(i, x) | (i, x) Array Int String setToArray set = listArray (1, Set.size set) ... Read More

Haskell Program to Convert List to Set

Akhil Sharma
Updated on 28-Mar-2023 14:59:18

925 Views

Haskell programming has internal functions like fromList, Set.fromList and foldr functions that can be used to convert list to set. In the first example, we are going to use (listToSet = Set.fromList) function and in the second example, we are going to call (set = Set.fromList xs) function directly from the main function. Whereas in third example, we are going to use (listToSet = foldr Set.insert Set.empty) function. Algorithm Step 1 − The qualified Data.Set module is imported. Step 2 − The listToSet function is defined using fromList function as, listToSet = Set.fromList. Step 3 − The program execution ... Read More

Advertisements