I have class Nodo
and class Lista
to call them from Main
; in Java I've done it but I do not know how to Ruby .
In Java I would have what it is:
class Nodo{
String nombre, id, tel; Nodo enlace = null ;
}
with their respective get and set.
And class Lista
that has all the insert by head methods, but I do not know how to do it in Ruby .
Help.
Class Node
public class Nodo {
int dato;
Nodo enlace;
/**
* @return the dato
*/
public int getDato() {
return dato;
}
/**
* @param dato the dato to set
*/
public void setDato(int dato) {
this.dato = dato;
}
/**
* @return the enlace
*/
public Nodo getEnlace() {
return enlace;
}
/**
* @param enlace the enlace to set
*/
public void setEnlace(Nodo enlace) {
this.enlace = enlace;
}
public Nodo(int x){
dato = x;
enlace = null;
}
public Nodo(int x, Nodo n){ //el constructor en Java
dato = x;
enlace = null;
}
}
-----------------------------------------------------------------------------
public class Lista {
private Nodo primero;
public Lista(){
primero = null;
}
public Lista insertarCabeceraLista(int entrada){
Nodo nuevo;
nuevo = new Nodo(entrada);
nuevo.enlace=primero;
primero = nuevo;
return this;
}
public void visualizar(){
Nodo n;
int k = 0;
n=primero;
while(n != null){
System.out.print(n.dato + " ");
n = n.enlace;
k++;
System.out.print((k%10 != 0 ? " " : "\n"));
}
}
}
That would be all my code in Java, now I need someone to help me work in Ruby