xakep.ru — паны троллят Oracle
кто как думает, на сколько это годный вариант добавления узла в двоичное дерево: public void addNode(int i) { if(i<this.currentNode.getPayload()) this.addLeft(i); else this.addRight(i); } private void addLeft(int i) { if(this.currentNode.getLeft() == null) this.currentNode.addLeft(i); else { this.currentNode = this.currentNode.getLeft(); addNode(i); } } private void addRight(int i) { if(this.currentNode.getRight() == null) this.currentNode.addRight(i); else { this.currentNode = this.currentNode.getRight(); addNode(i); } } ЗЫ currentNode - указатель на текущий узел, getPayload() - метод, возвращающий значение в узле (для теста использую Int)
вариант А:
public void bubbleSort()
{
if(!this.isEmpty())
{
for(int i=0; i<this.getLength(); i++)
{
for(int j=0+i; j<this.getLength(); j++)
{
if(this.getNode(i).getData() > this.getNode(j).getData())
swap(this.getNode(i), this.getNode(j));
}
}
}
}
вариант В:
public boolean bubbleSort()
{
if(this.isEmpty())
{
return true;
}
else
{
this.emersion();
return true;
}
}
private void emersion()
{
int len = this.getLength();
for(int i = 0; i < len; i++)
{
int data = this.getElement(i);
for(int j = 0; j < len-1; j++)
{
if(data < this.getElement(j))
this.swapElements(i, j);
}
}
}