gpt4 book ai didi

java - 制作正确的二叉树

转载 作者:行者123 更新时间:2023-12-01 15:59:43 24 4
gpt4 key购买 nike

    private void dcHullForUpperHull(List<Point> list, Point p, Point q) {
List<Point> upperH = new ArrayList<Point>();
List<Point> lowerH = new ArrayList<Point>();
int low = 0;
int high = list.size()-1;

System.out.println(list);
if(low<high) {

Point pivot = list.get((low+high)/2);

for (Point point : list) {
boolean bool = Determinate.isPointLeftSide(q, pivot, point);

if (bool == true ) {
upperH.add(point);
}
}
for (Point point : list) {
boolean bool = Determinate.isPointLeftSide(pivot, p, point);
boolean bool1 = Determinate.isPointOnLine(pivot, p, point);
if (bool == true || bool1==true) {
lowerH.add(point);
}
}

System.out.println(pivot.toString());
System.out.println(upperH.toString());
System.out.println(lowerH.toString());

dcHullForUpperHull(upperH, pivot, q);
dcHullForUpperHull(lowerH, p, pivot);



}
}

它打印:

[X :132.0  Y: 140.0angle0.0, X :162.0  Y: 116.0angle0.0, X :210.0  Y: 112.0angle0.0, `enter code here`X:258.0  Y: 117.0angle0.0]
X :162.0 Y: 116.0angle0.0
[X :210.0 Y: 112.0angle0.0, X :258.0 Y: 117.0angle0.0]
[X :132.0 Y: 140.0angle0.0, X :162.0 Y: 116.0angle0.0]
[X :210.0 Y: 112.0angle0.0, X :258.0 Y: 117.0angle0.0]
X :210.0 Y: 112.0angle0.0
[X :258.0 Y: 117.0angle0.0]
[X :210.0 Y: 112.0angle0.0]
[X :258.0 Y: 117.0angle0.0]
[X :210.0 Y: 112.0angle0.0]
[X :132.0 Y: 140.0angle0.0, X :162.0 Y: 116.0angle0.0]
X :132.0 Y: 140.0angle0.0
[]
[X :132.0 Y: 140.0angle0.0]
[]
[X :132.0 Y: 140.0angle0.0]

很明显我的二叉树不行!!还有一种方法“isPointLeftSide”会说该点在其确定的一行的左侧。但我的主要问题是:二叉树不好。并且我将有一些空的外部节点。请帮我谢谢

最佳答案

此代码不会创建二叉树。它几乎是快速排序(好吧,你进行枢轴、分区和递归调用,但不要再次将排序后的列表放在一起;因此几乎是)原始列表。您能具体说明您实际上想做什么吗?

关于java - 制作正确的二叉树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4275619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com