## Posts

Showing posts from April, 2018

In this post, we will discuss a method to add one to a number which is represented using nodes of the linked list.

Algorithm:
Reverse the linked list.Add one to the data field of the first node. While carry is not zero keep adding carry to the next node's data field if you reach the end of the linked list and the carry is not zero then we add a new node to the end of the linked list. Reverse the final linked list and return the head node of the linked list.

C++ ProgramJava programPython Program C++ Program Java Program Python Pr…

### Delete kth element from end of Linked List

In this post, we will discuss a method to delete the kth element from the end of the linked list. In order to delete the required node, we first need to find the kth element from the end of the linked list and then we can delete that element, so in one of the previous posts we have discussed a method to find kth element from the end of the linked listand In another post we have seen a method to delete node from linked list with the only pointer to that node, So combining the 2 methods we can delete the kth element from the end of the linked list.

Have a look at the below posts for an explanation of the methods used in this post
Finding kth element from the end of the Linked list Deleting element from the Linked List with only pointer to that nodeAlgorithm
Initialize 2 pointers first and second to head node Move node first to the kth node from the start Move both first and second node through the list till the first node reaches the last node At this point, the second node points to th…

### Deleting node with single pointer Linked List

In this post, we will discuss a simple method to delete a node when we have only the pointer of the node to be deleted and no link to the head or tail node. Deleting node with the only pointer to that node is one of the famous and very easy interview questions and is asked a lot. The method we use can be used for both simple or doubly linked list. To delete the given node, we can use the following method
Algorithm: Let the node to be deleted be called as the current node.Create a temp node to point to the next node.Now copy the contents of the temp node to the current node.copy the link field of the temp node to the link field of the current node.delete or free the memory pointer by the temp node.

C++ ProgramJava programPython Program C++ Program Java Program Python Program Sample input and output to check the program
You might also be interested in