【发布时间】:2016-10-13 02:25:38
【问题描述】:
所以,我们有一个家庭作业问题,要求我们创建一个角为 2^n 的超立方体。并且每个角在 x1、x2、x3...xn 的平面上都有一组 n 坐标。因此,一个 n=3 的超立方体具有如下坐标: 000、001、011、010 等在平面 x1、x2、x3 中。
编写这个程序的重点是有一个递归方法和一个迭代方法来“走”过超立方体,并且恰好通过每个角落一次,而不会重叠它的轨迹。教授还要求我们的 Corner 对象是超立方体类中的一个嵌套类。到目前为止,这是我想出的:
公共类超立方体 {
private Corner[] walk;
private int size;
private final int ZERO = 0;
private int count;
public Hypercube(int n) throws IllegalHypercubeException {
if (n < 0) {
throw new IllegalHypercubeException("Please enter a positive integer");
} else {
this.size = n;
this.count = 0;
this.walk = new Corner[(int) Math.pow(2, n)];
}
}
public class Corner
{
private int[] coordinates;
public Corner() {
this.coordinates = new int[size];
}this.coordinates = coordinates;
}
在我什至可以在 walk 方法中递归排序之前,我发现设置坐标最困难。我的意思是如何设置 2^n 个角的立方体的每个角的所有坐标?
【问题讨论】:
标签: java arrays data-structures computer-science