Dobry den,
dostali sme v skole ukol
http://img600.imageshack.us/…02/ukol3.png
Ja som napisal nasledujuci kod ..ktory mi test nezobral ..s hlaskou ..
Exception in thread "main" java.lang.AssertionError: Vami vraceny strom neni v poradku
at Homework3Test.main(Homework3Test.java:103)
Test NEPROSEL.
Prosim vas mohol by sa prosim niekto na to pozriet > a poradit mi ?
class Adapter implements Node {
BinaryNode adapter;
Adapter[] children;
Adapter parent;
public Adapter(BinaryNode adapter) {
this.adapter = adapter;
}
public void printChildren(){
for (int i = 0; i < children.length; i++) {
System.out.println("dieta "+i+"."+" "+ children[i].getName());
}
}
public void setParent(Adapter parent){
this.parent = parent;
}
@Override
public String getName() {
return adapter.getName();
}
@Override
public Adapter getParent() {
return parent;
}
@Override
public Adapter[] getChildren() {
Adapter[] pomocny = new Adapter[1];
Adapter[] deti = new Adapter[0];
Adapter lavy = new Adapter(adapter.getLeftChild());
if (lavy.adapter != null){
lavy.setParent(this);
pomocny[0] = lavy;
Adapter pravy = new Adapter(lavy.adapter.getRightChild());
while(pravy.adapter != null){
pravy.setParent(this);
deti = new Adapter[pomocny.length + 1];
System.arraycopy(pomocny, 0, deti, 0, pomocny.length);
deti[deti.length - 1] = pravy;
pomocny = deti;
System.arraycopy(deti, 0, pomocny, 0, deti.length);
pravy = new Adapter(pravy.adapter.getRightChild());
}
return deti;
}
else {
return deti;
}
}
}
class Homework3 {
static Node adapt(BinaryNode n){
Node bod = new Adapter(n);
return bod;
}
}