ma quante ne fai.. :)
codice:
function Node(name, secondName, phone)
{
this.name = name;
this.secondName = secondName;
this.phone = phone;
this.right = null; // figlio destro
this.left = null; // figlio sinistro
this.parent = null; // padre
}
function binTree(name, secondName, phone)
{
this.rootNode = new Node(name, secondName, phone);
this.cardinality = 1;
}
binTree.prototype.visit = function ()
{
this.strReturn = ""; // una stringa vuota
return this.visitPtr(this.rootNode);
}
binTree.prototype.visitPtr = function (visitNode)
{
if (visitNode != null)
{
//this.visitPtr(visitNode.left, txt);
this.strReturn += visitNode.secondName;
//this.visitPtr(visitNode.right, txt);
}
else
{
// Qui mi gestirò poi l'eccezione...
}
return this.strReturn; // e la restituisco la stringa che prima era vuota
}
albero = new binTree("naighes", "superNaighes", "144");
vis_txt = albero.visit(); // e qui dovrebbe ricevere la stringa...
ATTENTO:
tu hai usato questa riga:
codice:
this.strReturn += this.visitNode.secondName
ma è sbagliata, perchè vistNode è una variabile locale passata alla funzione, quindi:
codice:
this.strReturn += visitNode.secondName
senza il this.
Poi, la funzione visit non restituisce niente:
codice:
binTree.prototype.visit = function ()
{
this.strReturn = "";
return this.visitPtr(this.rootNode);
}
e allora come fa a riempire il campo di testo? Quindi, visitPtr restutisce un valore, e visit a sua volta lo deve restituire.
codice:
binTree.prototype.visit = function ()
{
this.strReturn = "";
var nuovoValore = this.visitPtr(this.rootNode);
return nuovoValore;
}
contratto:
codice:
binTree.prototype.visit = function ()
{
this.strReturn = "";
return this.visitPtr(this.rootNode);
}