Listas Ligadas
NODOLISTA Y ASI QUEDARA:
///clase (registro) que sirve para generar
nodos de dos tipos de formas (2
constructores)
public class NodoLista {
// 2 camposObject Info;
NodoLista Liga;
//PRIMER CONSTRUCTOR
public NodoLista(Object dato){
Info = dato;
Liga = null;
}
//SEGUNDO CONSTRUCTOR
public NodoLista(Object dato, NodoLista
liga){
Info = dato;this.Liga = liga; /////el this solo es para
decir que la primera "liga"
} ////es global
}
ESTE ES EL ARCHIVO LLAMADO LISTA , ES
DONDE SE REALIZAN LAS FUNCIONES PARA
EJECUTAR LOS CONSTRUCTORES,ASI DEBE
DE QUEDAR:
//// clase que manipula a los punteros para
manipular los nodos en la memoria
public class Lista{
// declarar los punteros!!!
NodoLista Primero, ultimo, aux, nuevo,
ant, post;public Lista(){
Primero = ultimo = aux = nuevo = ant =
post = null;
}
public void insertarAlFrente(Object dato){
if(Primero==null){// si la lista esta vacia
Primero = new NodoLista(dato);ultimo=Primero;
}
else{////ya hay mas nodos en la lista
nuevo = new NodoLista(dato);
ultimo.Liga = nuevo;
ultimo = nuevo;
}despliegaLista();
}
public void insertarAtras(Object dato){if(Primero==null){// si la lista esta vacia
Primero = new NodoLista(dato);
ultimo=Primero;
}
else{
nuevo = new NodoLista
(dato,Primero);
Primero = nuevo;
}despliegaLista();
}
public voiddespliegaLista(){
aux = Primero;
System.out.println ("##########LISTA
COMPLETA#########");
while (aux != null) {
System.out.println (aux.Info);
aux = aux.Liga;
}
System.out.println ("##########LISTACOMPLETA#########");
}
/////////INSERTAR ANTES DE //////////
public void insertarAntesDe(Object
DatoB,Object DatoI){
if(Primero==null){
System.out.println ("lista vacia");
}
else{/////haydatos
if(buscar(DatoB)== true){
///////EMPEZAR A REALIZAR EL
METODO
if(aux==Primero){///caso 1
nuevo= new NodoLista
(DatoI,Primero);
Primero = nuevo;
}
else{//en caso de que no este al...
Regístrate para leer el documento completo.