我正在做作业,要求我创建一个菜单驱动的词典,用户可以在其中输入或删除该单词。但是,我已经创建了方法,对于删除方法,它会检查单词,直到删除某些内容为止。然后,即使元素不在列表中,每次删除时也会将其删除。我正在尝试从用户输入中删除单词。第一次删除后,始终将其删除。
void removeWord(String s) {
WordMeaningNode current = list;
WordMeaningNode back = null;
boolean found = false;
while (current != null && !found) {
if (s.compareTo(aux.wordmeaning.getWord()) == 0) {
if (back == null) {
dellist = current;
list = current.next;
} else {
dellist = current;
back.next = current.next;
}
found = true;
} else {
back = current;
current = current.next;
}
}
}
情况2:
try {
String wordremoved = GetData.getString("Enter Word");
list.removeWord(wordremoved);
deleted_list.addWord(new WordMeaning(list.getList().wordmeaning.getWord(), " "));
JOptionPane.showMessageDialog(空,“已删除单词”,“警报”,JOptionPane.INFORMATION_MESSAGE); } catch(NullPointerException e){
}
这是我从用户那里获取输入以精简单词的情况
这是我的方法,谁能帮助我做错了事情