Java program to sort the elements of the Circular Linked List8 Jan 2025 | 3 min read In this program, we will create a circular linked list and sort the list in ascending order. In this example, we maintain two nodes: current which will point to head and index which will point to next node to current. The first loop, keep track of current and second loop will keep track of index. In the first iteration, current will point to 9. The index will point to node next to current which in this case is 5. 9 is compared with 5, since 9 > 5, swap data of index node with the current node. Now, the current will have 5. Now, 5 will be compared to 2. Again 5 > 2, swap the data. Now current will hold 2 and index will hold 7. 2 < 7, nothing will be done. The index will be incremented and pointed to 3.2< 3. Nothing will be done. In this way, we will have a minimum value node in the first position. Then, we will keep on finding minimum element in the rest of the list until the list is completely sorted. 9->5->2->7->3 Algorithm
Program:Output: Original list: 70 90 20 100 50 Sorted list: 20 50 70 90 100 Next TopicJava Programs |
A prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers cannot be divided by other than itself or 1. For example, 2, 3, 5, 7, 11, 13, 17... are the prime numbers. Note: 0 and...
6 min read
Java Convert String to double We can convert String to double in java using Double.parseDouble() method. Scenario It is generally used if we have to perform mathematical operations on the string that contains double number. Whenever we get data from textfield or textarea, entered data is received as a...
1 min read
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to discuss...
5 min read
Palindromes are fascinating linguistic constructs that have intrigued minds for centuries. In simple terms, a palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward. In the realm of programming, creating a program to determine whether a...
9 min read
In this section, we will learn what is xylem and phloem number and also create Java programs to check if the given number is xylem or phloem. The xylem and phloem number program frequently asked in Java coding tests and academics. Xylem and Phloem Number A number N...
2 min read
In Java, to find the square root of a number is very easy if we are using the pre-defined method. Java Math class provides sqrt() method to find the square root of a number. In this section, we will create a Java program to find the...
3 min read
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, HCL, IBM, and Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are...
10 min read
Binary search is used to search a key element from multiple elements. Binary search is faster than linear search. In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays.sort(arr) method. Binary Search Algorithm...
8 min read
In this program, we will create a doubly linked list and delete a node from the middle of the list. If the list is empty, display the message "List is empty". If the list is not empty, we will calculate the size of the list...
7 min read
In this section, we will learn what is a sphenic number and also create Java programs to check if the given number is sphenic or not. The sphenic number program frequently asked in Java coding tests and academics. Sphenic Number A positive integer n is called a sphenic...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India