Home > Back-end >  Singly linked lists the minimum to delete
Singly linked lists the minimum to delete

Time:10-04

Recently, just learning Java, teacher assigned a topic, the smallest element of request to delete the lead node singly linked lists, struggling with delete all the smallest element should be how to implement, have no idea, bosses to give directions

CodePudding user response:

Traverse again to find out the minimum first, traverse again found that equals the minimum element node deletion

CodePudding user response:

Define a variable before traversal of min=Integer. Max, when traversing a node if the node value is less than min, save the node, after the traversal will save node to change the value of its next node values and then remove the next node

CodePudding user response:

reference 1st floor yyfhz response:
first traverse again to find the minimum value, traverse again found that equals the minimum element node deletion of
figured it out

CodePudding user response:

Traversal time is ok, the code is as follows:
 Node currentNode=list. The head; 
The Node minNodefront=null;
The Node minNode=list. The head;
While (currentNode. Next!=null) {
If (minNode. Data & gt; CurrentNode. Next. Data) {
MinNode=currentNode. Next;
MinNodeFront=currentNode;
}
The node=node. The next;
}

If (minNodefront==null) {
List. The head=minNode;
} else {
MinNodeFront. Next=minNode. Next;
}


Administrators also said I irrigate, deleted my comment, not endure
  • Related