public class lista {
public class nodo {
private int dato=0;
private nodo next=null,prev=null;
protected nodo(int d){
dato=d;
}
protected void setDato(int d){
dato=d;
}
protected int getDato(){return dato;}
protected void setNext(nodo n){next=n;}
protected void setPrev(nodo n){prev=n;}
protected nodo getNext(){return next;}
protected nodo getPrev(){return prev;}

}




private nodo L=null, P=null;
private int longitud=0;

public lista(){L=null;longitud=0;}
public void fin(){
P=L;
if(L==null){}
else if(P.getNext()==P){}
else {P=P.getNext();
while(P.getNext()!=L){P=P.getNext();}}
}
public void insertaInicio(int d){
nodo n=new nodo(d);
if(L==null){L=n;n.setNext(n);n.setPrev(n);}
else{fin();n.setNext(L);n.setPrev(P);L=n;P.setNext(n);n.getNext().setPrev(n);}
}
public voidinsertaFinal(int d){

nodo n=new nodo(d);
if(L==null){L=n;n.setNext(n);n.setPrev(n);}
else{fin();n.setPrev(P);n.setNext(L);P.setNext(n);L.setPrev(n);}
}
public int buscaValor(int d){
int contador=1;
P=L;
if(L==null)return -1;
else if(P.getDato()==d)return 0;
else{P=P.getNext();
if(P!=L){while(P.getDato()!=d&&P!=L){P=P.getNext();contador++;}return contador;}
else{return -1;}
}

}
public boolean elimina(int d){
P=L;
if(L==null)return false;
else if(L.getDato()==d&&L.getNext()==L){L=null;return true;}
else{P=P.getNext();
while(P.getNext().getDato()!=d&&P.getNext()!=L)P=P.getNext();
if(P.getNext()!=L){P.getNext().getNext().setPrev(P);P.setNext(P.getNext().getNext());longitud--;return true;}
else{return false;}
}

}
public void insertaAntes(int d,int [continua]

Leer Ensayo Completo

Cite este ensayo

APA

(2010, 04). Lista doble ligada en java. BuenasTareas.com. Recuperado 04, 2010, de http://www.buenastareas.com/ensayos/Lista-Doble-Ligada-En-Java/226109.html

MLA

"Lista doble ligada en java" BuenasTareas.com. 04 2010. 2010. 04 2010 <http://www.buenastareas.com/ensayos/Lista-Doble-Ligada-En-Java/226109.html>.

MLA 7

"Lista doble ligada en java." BuenasTareas.com. BuenasTareas.com, 04 2010. Web. 04 2010. <http://www.buenastareas.com/ensayos/Lista-Doble-Ligada-En-Java/226109.html>.

CHICAGO

"Lista doble ligada en java." BuenasTareas.com. 04, 2010. consultado el 04, 2010. http://www.buenastareas.com/ensayos/Lista-Doble-Ligada-En-Java/226109.html.