Scopo
Aggiunge un oggetto come ultimo elemento dell'array e restituisce il suo indice.
Sintassi
int index = Array.addObject(Oggetto)
Argomenti
Oggetto | Oggetto da inserire alla fine dell'array. |
Valore di ritorno
Viene restituita la posizione in cui l'elemento è stato inserito nell'array.
Esempio di codice
// ****************************************************************
// Sposta l'ultimo piano della torre di sinistra a quella di destra
// ****************************************************************
public void Torre.LeftToRight()
{
//
if (this.Left.length() > 0)
{
Piano p = null //
//
p = this.Left.getObject(this.Left.length() - 1)
//
// Se in R c'è qualcosa devo verificare di poterlo mettere..
if (this.Right.length() > 0)
{
Piano p1 = null //
p1 = this.Right.getObject(this.Right.length() - 1)
//
// Posso mettere un piano sopra un altro solo se il valore è minore
if (p1.Valore < p.Valore)
{
return
}
}
//
this.Left.remove(this.Left.length() - 1)
//
this.Right.addObject(p)
//
this.Counter = this.Counter + 1
TorreDiHanoi.refresh(1, -1)
}
}
// Sposta l'ultimo piano della torre di sinistra a quella di destra
// ****************************************************************
public void Torre.LeftToRight()
{
//
if (this.Left.length() > 0)
{
Piano p = null //
//
p = this.Left.getObject(this.Left.length() - 1)
//
// Se in R c'è qualcosa devo verificare di poterlo mettere..
if (this.Right.length() > 0)
{
Piano p1 = null //
p1 = this.Right.getObject(this.Right.length() - 1)
//
// Posso mettere un piano sopra un altro solo se il valore è minore
if (p1.Valore < p.Valore)
{
return
}
}
//
this.Left.remove(this.Left.length() - 1)
//
this.Right.addObject(p)
//
this.Counter = this.Counter + 1
TorreDiHanoi.refresh(1, -1)
}
}
Ultima modifica: 12/03/2012 / Validità: da 9.1.4040