public LinkNode find(int id) { LinkNode node = firstNode; // 循环递归查找 while (node.getId() != id) { if (node.getNext() != null) { node = node.getNext(); } else { return null; } } return node; }
public LinkNode remove(int id) { LinkNode needDelete = firstNode; LinkNode previNode = firstNode; while (needDelete.getId() != id) { if (needDelete.getNext() == null) { return null; } else { previNode = needDelete; needDelete = needDelete.getNext(); } } if (needDelete.equals(firstNode)) { firstNode = firstNode.getNext(); } else { previNode.setNext(needDelete.getNext()); } return needDelete; }