1 Star 0 Fork 0

besti1923/JAVA

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SearchTest.java 3.65 KB
一键复制 编辑 原始数据 按行查看 历史
yifei 提交于 5年前 . seven experiment
package text.java;
import java.util.Scanner;
public class SearchTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
searching asl = new searching();
int target = 0,i,j=0;
int[] arr = {2309,19,23,1,68,25,84,27,55,11,10,2309};
System.out.print("列表:");
System.out.println(asl.print(arr));
asl.sort(arr);
System.out.println("排序:"+asl.print(arr));
System.out.print("顺序查找,输入要查找的数:");
target = scan.nextInt();
System.out.println("是否找到:"+asl.order(arr,target));
System.out.println("找到的数是:"+asl.binaryshow(arr,0,11,5,target));
System.out.println();
System.out.print("折半查找,输入要查找的数:");
target = scan.nextInt();
System.out.println("是否找到:"+asl.binary(arr,0,11,5,target));
System.out.println("找到的数是:"+asl.binaryshow(arr,0,11,5,target));
System.out.println();
System.out.print("线性探查法查找,输入要查找的数:");
target = scan.nextInt();
int result[] = asl.hash(arr);
int re = asl.hashsearch(result,target);
if(re==0)
System.out.println("查找失败!数组中无此数!");
else
System.out.println("查找成功!查找到的数是:"+re);
System.out.println();
System.out.print("二叉排序树查找,输入要查找的数:");
int a = scan.nextInt();
Compareable target1;
target1 = new Compareable(a);
int[] b = new int[12];
BinaryTree e=new BinaryTree();
e.s(arr);
Compareable tree = e.get();
boolean k = treesearch.erchashu(tree,target1);
System.out.println("是否找到:"+k);
System.out.println();
System.out.print("链地址法查找,输入要查找的数:");
target = scan.nextInt();
Linked[] linked = new Linked[12];
for(i=0;i<12;i++)
linked[i] = new Linked(arr[i]);
Linked[] re1 = asl.linkedhash(linked);
int ree = asl.linkedsearch(re1,target);
if(ree==0)
System.out.println("查找失败!数组中无此数!");
else
System.out.println("查找成功!查找到的数是:"+ree);
System.out.println();
System.out.print("插值查找,输入要查找的数:");
target = scan.nextInt();
asl.sort(arr);
System.out.println("查找到的数是:"+asl.InsertionSearch(arr,target,0,11));
System.out.println();
System.out.print("斐波那契查找,输入要查找的数:");
target = scan.nextInt();
System.out.println("是否找到:"+asl.FibonacciSearch(arr,target));
System.out.println();
System.out.print("分块查找,输入要查找的数:");
target = scan.nextInt();
int re2 = asl.blocking(arr,target);
if(re2==0)
System.out.println("查找失败!数组中无此数!");
else
System.out.println("查找成功!查找到的数是:"+re2);
}
public static class treesearch {
public static boolean erchashu(Compareable tree, Compareable target)
{
while (tree!=null)
{
if(tree.geti()<target.geti())
{
tree=tree.next;
}
else if (tree.geti()>target.geti())
{
tree = tree.secondnext;
}
else if(tree.geti()==target.geti())
return true;
}
return false;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/besti1923/java.git
git@gitee.com:besti1923/java.git
besti1923
java
JAVA
master

搜索帮助