【发布时间】:2018-10-08 11:29:42
【问题描述】:
您好,我是一名新手程序员,试图弄清楚如何仅使用开头的第一个字母在二叉搜索树中搜索字符串,例如,如果只搜索字母“L”,它应该会显示所有以那个字母开头的名字。以下是目前我们如何搜索全名的方法。
public void searchByName() throws IOException//My pride and joy
{
String exit=null;//to exit the inner while loop
Boolean end=false;// exit the outer while loop
while(end!=true) //search author by first name loop
{
@SuppressWarnings("resource")
Scanner keyboard = new Scanner(System.in);
System.out.printf("Please enter the Author's Last and First:(please enter in this format(Johnson, Cevion)\n");
String name = keyboard.nextLine();
System.out.println("This is what we found!!\n");
System.out.println(findFullName(name));
System.out.printf("Do you want to search again?? Yes or No\n");//search again loop
exit = keyboard.nextLine();
while(!exit.equalsIgnoreCase("yes")&&!exit.equalsIgnoreCase("no"))//yes or no only loop
{
System.out.printf("Invaild choice please enter: Yes or No\n");
exit = keyboard.nextLine();
}
if(exit.equalsIgnoreCase("yes"))
end=false;
if(exit.equalsIgnoreCase("no"))
end=true;
}
}
【问题讨论】:
-
您显示的代码实际上并不相关。而且它通常不是 binary 树,因为有超过 2 种类型的字母。例如查看en.wikipedia.org/wiki/Trie 并在互联网上搜索更多内容。您目前缺少您可能在此处提出的问题的详细信息。提示:树通常涉及递归。
标签: java string binary-search-tree letters