java - how to delete a node from linkedlist?

前端 未结 4 679
长发绾君心
长发绾君心 2020-12-11 09:41

This code is a table that has an option to Inert name, delete, show, and quit .

this code run\'s well but my only problem is on how to delete a chosen name in a nod

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 09:54

    while (node != null) {
    
                if (node.getNext() == null || head.getNext() == null) {
                    break;
    
                } else if (head.getData() == data) {
                    head = head.getNext();
                } else if (node.getNext().getData()==null&&data==null||node.getNext().getData().equals(data)) {
                    node.setNext(node.getNext().getNext());
                } else {
                    node = node.getNext();
                }
            }
        }
    
        return head;
    

提交回复
热议问题