Skip to main content

Deleting a Node by passing data in LInkedList

Deleting a Node by passing data in LInkedList:-

The node can be deleted by passing the data value in a function.Here we have three pointers one to traverse the list other to point current node and third one to point previous of current node.

//deleting a given key
 public Node deleteKeyNode(Node head,int key)
  //traverse pointer
  Node temp=head;
  //previous pointer
  Node prevtemp=temp;
   //when key is at head position
    System.out.println("head is deleted");
    return head;
   //when key is at any position other than head
  return head;



Popular posts from this blog

Selection Sort in JAVA

What is selection sort? It is a sorting technique that is based on the partitioning of array into two parts, sorted and unsorted. The process is:- 1) Find minimum element in unsorted array. 2) Swap the element at the end of sorted array. when i=0 we don't have any sorted array so element will be replaced from first element later the sorted array end will growas the index. Steps:- underline elements are sorted array, the length is increasing with each minimum element added at the end. minimum element11 11 25 12 22 64 minimum element12 11 12 25 22 64 minimum element22 11 12 22 25 64 minimum element25 11 12 22 25 64 minimum element64 11 12 22 25 64 Program:- package sorting ; public class SelectionSort { //function to print array public static void print ( int [] arr ) { for ( int i = 0 ; i <= arr . length - 1 ; i ++) System . out . print ( " " + arr [ i ]); System . out . printl

Best LeetCode Lists for Interviews

Here is a list of some of the best questions asked in interviews:-  Must do 75 Must do 60 Must do medium:- Must do Easy:- Graph:-  Dynamic Programming:-  FaceBook interviews:-  Amazon Interviews:-  Google Interviews:-