Java program to insert a new node at the beginning of the Circular Linked List17 Mar 2025 | 3 min read In this program, we will create a circular linked list and insert every new node at the beginning of the list. If the list is empty, then head and tail will point to the newly added node. If the list is not empty, then we will store the data of the head into a temporary node temp and make new node as the head. This new head will point to the temporary node. In simple words, the newly added node will be the first node(head) and previous head(temp) will become the second node of the list. ![]() After inserting new node to the beginning of the list. ![]() New represents the newly added node. Earlier A was the head of the list. When new is added to the beginning of the list, new will become the new head, and it will point to the previous head, i.e., A. Algorithm
a. display() will show all the nodes present in the list.
Program:Output: Adding nodes to the start of the list: 1 Adding nodes to the start of the list: 2 1 Adding nodes to the start of the list: 3 2 1 Adding nodes to the start of the list: 4 3 2 1 Next TopicJava Programs |
In this program, we need to remove the duplicate nodes from the given singly linked list. Original List: List after removing duplicate nodes: In the above list, node 2 is repeated thrice, and node 1 is repeated twice. Node current will point to head, and index will point...
7 min read
In this program, we need to calculate the sum of elements in each row and each column of the given matrix. Above diagram shows the sum of elements of each row and each column of a matrix. Algorithm STEP 1: START STEP 2: DEFINE rows, cols, sumRow, sumCol STEP 3:...
3 min read
Java Convert Date to String We can convert Date to String in java using format() method of java.text.DateFormat class. format() method of DateFormat The format() method of DateFormat class is used to convert Date into String. DateFormat is an abstract class. The child class of DateFormat is SimpleDateFormat. It...
2 min read
In this program, we need to search a node in the given singly linked list. Identity Matrix To solve this problem, we will traverse through the list using a node current. Current points to head and start comparing searched node data with current node data. If they...
5 min read
Java Convert Date to Timestamp We can convert Date to Timestamp in java using constructor of java.sql.Timestamp class. The constructor of Timestamp class receives long value as an argument. So you need to convert date into long value using getTime() method of java.util.Date class. You can also format the...
2 min read
In this program, we need to count and print the number of elements present in the array. The number of elements present in the array can be found by calculating the length of the array. Length of above array is 5. Hence, the number of elements present...
1 min read
It is very interesting 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...
6 min read
Java program to print the following pattern on the console Algorithm: STEP 1: START STEP 2: SET coe=1, rows= 6. STEP 3: SET i=0. REPEAT STEP 4 to STEP 11 UNTIL i STEP 4: SET space = 1. REPEAT STEP 5 and STEP 6 UNTIL space<(rows ?i) STEP 5: PRINT...
2 min read
Java Convert int to double We can convert int to double in java using assignment operator. There is nothing to do extra because lower type can be converted to higher type implicitly. It is also known as implicit type casting or type promotion. Java int to double Example Let's...
1 min read
Java Program to find Second Smallest Number in an Array We can find the second smallest number in an array in java by sorting the array and returning the 2nd element. Let's see the full example to find the second smallest number in java array. public class SecondSmallestInArrayExample{ public...
2 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