Professional Documents
Culture Documents
MAIN
package ledccoboy;
import javax.swing.JOptionPane;
int opc=0,elemento,op;
do{
do{
try{
opc=Integer.parseInt(JOptionPane.showInputDialog(null,
switch(opc){
case 1:
do{
try{
elemento=Integer.parseInt(JOptionPane.showInputDialog(null,"Agregar elemento
a la lista","AGREGAR NODO AL INICIO",3));
Coboy.agregarInicio(elemento);
break;
}catch(NumberFormatException e){
op = JOptionPane.showConfirmDialog(null,"DATO
INCORRECTO\n"+"¿DESEA VOLVER INTERTARLO?");
if(op == 1){
break;
if(op == 2)
break;
}while(true);
break;
case 2:
do{
try{
elemento=Integer.parseInt(JOptionPane.showInputDialog(null,"Agregar elemento
a la lista","AGERGAR NODO AL FINAL",3));
Coboy.agregarFinal(elemento);
break;
}catch(NumberFormatException e){
op = JOptionPane.showConfirmDialog(null,"DATO
INCORRECTO\n"+"¿DESEA VOLVER INTERTARLO?");
if(op == 1){
break;
if(op == 2)
break;
}while(true);
break;
case 3:
if(op == 0)
Coboy.mostrarInicioFin();
if(op == 1){
break;
break;
case 4:
if(op == 0)
Coboy.mostrarFinInico();
if(op == 1){
break;
}
break;
case 5:
op = JOptionPane.showConfirmDialog(null,"¿DESEA ELIMINAR EL
INCIO DE LA LSITA?");
if(op == 0)
Coboy.eliminarAlInicio();
if(op == 1){
break;
break;
case 6:
op = JOptionPane.showConfirmDialog(null,"¿DESEA ELIMINAR EL
FINAL DE LA LSITA?");
if(op == 0)
Coboy.eliminarAlFinal();
if(op == 1){
break;
break;
case 7:
do{
try{
elemento =
Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese elemento a
eliminar","ELIMINAR",0));
if(Coboy.buscar(elemento)){
op = JOptionPane.showConfirmDialog(null,"DESEA ELIMINAR
ELEMENTO");
if(op == 0){
Coboy.eliminarEspecifico(elemento);
JOptionPane.showMessageDialog(null,"Elemnto eliminado
exitosamente", "ELEMENTO ELIMINADO",0);
break;
if(op == 1){
break;
else
JOptionPane.showMessageDialog(null,"EL ELEMENTO
SELECCIONADO NO EXISTE","NO EXISTE",0);
}catch(NumberFormatException e){
op = JOptionPane.showConfirmDialog(null,"DATO
INCORRECTO\n"+"¿DESEA VOLVER INTERTARLO?");
if(op == 1){
break;
if(op == 2)
break;
}while(true);
break;
case 8:
do{
try{
elemento =
Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese elemento a
buscar","BUSCADOR",0));
if(Coboy.buscar(elemento))
JOptionPane.showMessageDialog(null,"EL ELEMENTO
SELECCIONADO SI EXISTE","BUSCADOR",-1);
else
JOptionPane.showMessageDialog(null,"EL ELEMENTO
SELECCIONADO NO EXISTE","BUSCADOR",0);
break;
}catch(NumberFormatException e){
op = JOptionPane.showConfirmDialog(null,"DATO
INCORRECTO\n"+"¿DESEA VOLVER INTERTARLO?");
if(op == 1){
break;
if(op == 2)
break;
}while(true);
break;
case 9:
JOptionPane.showMessageDialog(null,"HASTA LA PROXIMA\n"
+"VUELVA PRONTO","FIN DEL PROGRAMA",1);
System.exit(0);
break;
default:
}catch(NumberFormatException e){
if(e.getMessage().equals("null"))
System.exit(0);
else
JOptionPane.showMessageDialog(null,"OPCION INGRESADA ES
INCORECTA\n","OPCION INCORECTA",0);
}while(true);
}while(opc != 9);
}//main
LISTA
package ledccoboy;
import javax.swing.JOptionPane;
public ListaDC(){
inicio=fin=null;
return inicio==null;
}
if(!estaVacia()){
inicio=new NodoDobleC(elem,inicio,fin) ;
inicio.siguiente.anterior=inicio;
fin.siguiente = inicio;
inicio=fin=new NodoDobleC(elem);
if(!estaVacia())
fin=new NodoDobleC(elem,inicio,fin);
inicio.anterior = fin;
fin.anterior.siguiente = fin;
else{
inicio=fin=new NodoDobleC(elem);
}
public void mostrarInicioFin (){ //incio al fin
if(!estaVacia()){
String data="";
NodoDobleC aux=inicio;
do{
data += "["+aux.dato+"]<=>";
//data=data+"["+aux.dato+"]<=>";
aux=aux.siguiente;
}while(aux != inicio);
else
if(!estaVacia()){
String data="";
NodoDobleC aux=fin;
do{
data += "["+aux.dato+"]<=>";
//data=data+"["+aux.dato+"]<=>";
aux=aux.anterior;
}while(aux != fin);
else
JOptionPane.showMessageDialog(null,"NO HAY DATOS QUE MOSTRAR","NO
HAY DATOS",-1);
int elemento=inicio.dato;
if(inicio==fin)
inicio=fin=null;
else{
inicio=inicio.siguiente;
inicio.anterior=fin;//apunta a fin
fin.siguiente = inicio;
int elemento=fin.dato;
if(inicio==fin)
inicio=fin=null;
else{
fin = fin.anterior;
fin.siguiente = inicio;
inicio.anterior = fin;
}
public void eliminarEspecifico(int elem){
if(!estaVacia()){
while(ant!= fin){
if(aux.dato == elem){
if(inicio == fin){
break;
else{
inicio = inicio.siguiente;
aux.siguiente = null;
inicio.anterior = fin;
fin.siguiente = inicio;
break;
ant.siguiente = null;
fin.siguiente = null;
inicio.anterior = null;
fin.anterior = null;
fin = ant;
fin.siguiente = inicio;
inicio.anterior = fin;
break;
}
else{
ant.siguiente = aux.siguiente;
aux.anterior = null;
aux.siguiente.anterior = ant;
break;
else{
ant = aux;
aux = aux.siguiente;
if(!estaVacia()){
do{
if(aux.dato==elem)
return true;
aux = aux.siguiente;
}while(aux!=inicio);
return false;
}
NODO
package ledccoboy;
int dato;
dato = elem;
siguiente = sig;
anterior = ant;
dato = elem;