Java program to delete a node from the middle of the singly linked list17 Mar 2025 | 5 min read In this program, we will create a singly linked list and delete a node from the middle of the list. To accomplish this task, we will calculate the size of the list and then divide it by 2 to get the mid-point of the list. Node temp will point to head node. We will iterate through the list till midpoint is reached. Now, the temp will point to middle node and node current will point to node previous to temp. We delete the middle node such that current's next node will point to temp's next node. ![]() Consider the above example, mid-point of the above list is 2. Iterate temp from head to mid-point. Now, temp is pointing to the mid node which needs to be deleted. In this case, Node is the middle node which needs to be deleted. The node can be deleted by making node 2's next (current) to point to node 3 (temp's next node). Set temp to null. Algorithm
a. deleteFromMid() will delete a node from the middle of the list:
a. display() will display the nodes present in the list:
Program:Output: Original List: 1 2 3 4 Updated List: 1 3 4 Updated List: 1 4 Updated List: 4 Updated List: List is empty Next TopicJava Programs |
In this program, we need to find the transpose of the given matrix and print the resulting matrix. Transpose of Matrix Transpose of a matrix can be found by interchanging rows with the column that is, rows of the original matrix will become columns of the new...
4 min read
It is a 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...
3 min read
In this section, we will write the Java programs to check if a number is positive or negative. We have used the following ways to check the number is positive, negative, or zero. Using Relational Operator Using Math.signum() Method Using Integer.signum() Method Using Bit Shift Operator Using ArrayList class Using Relational Operator To...
5 min read
In this program, the given ternary tree will be converted into a corresponding doubly linked list. The ternary tree is a hierarchical data structure in which each node can have at most three children. This can be accomplished by traversing the ternary tree in a pre-order...
6 min read
The singly linked list is a linear data structure in which each element of the list contains a pointer which points to the element in the list. Each element in the singly linked list is called a node. Each node has two components: data...
5 min read
In this program, we need to multiply two matrices and print the resulting matrix. Product of two matrices The product of two matrices can be computed by multiplying elements of the first row of the first matrix with the first column of the second matrix then, add...
6 min read
In this program, we need to check whether given singly linked list is a palindrome or not. A palindromic list is the one which is equivalent to the reverse of itself. The list given in the above figure is a palindrome since it is equivalent to...
7 min read
Java Program Number to Word In this section, we will create a Java program that converts the given number into words. For example, if the given number is 54,297 then the output should be Fifty-Four Thousand Two Hundred Ninety-Seven. Let's create a Java program for the same. NumberToWordExample1.java class...
9 min read
In this program, we create a doubly linked list and insert a new node in the middle of list. If list is empty, both head and tail will point to new node. If list is not empty, then we will calculate the size of the...
8 min read
In this program, we need to find the most repeated word present in given text file. This can be done by opening a file in read mode using file pointer. Read the file line by line. Split a line at a time and store in...
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