Java - Como hacer que una cola normal se comporte como dinamica

 
Vista:

Como hacer que una cola normal se comporte como dinamica

Publicado por Alex (2 intervenciones) el 07/06/2016 22:41:00
me pueden ayudar como puedo hacer que un elemento de mi cola no se elimine
ya tengo hecho el codigo de cola y cola dinamica me podrian dar una idea
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Como hacer que una cola normal se comporte como dinamica

Publicado por Brian Cid (3 intervenciones) el 08/06/2016 03:29:44
Bueno para esta respuesta tengo lo siguiente para ti son 3 archivos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
///////////////GENERA NODOS PARA LISTAS DOBLES////////////////////
 
class NodoListaCola{
    ////3 campos
    Object info;
    NodoListaCola Izq;/////////////asi se declara para apuntar a un dato igual a ellos
    NodoListaCola Der;
 
    /////////////primer constructor/*/////////////////
    public NodoListaCola(Object Dato){
        this.info = Dato;
        this.Izq = null;
        this.Der = null;
    }
 
    /////////////////segundo constructor///////////////
    public NodoListaCola(NodoListaCola Izq, Object Dato){
        this.Izq = Izq;
        this.info = Dato;
        this.Der = null;
    }
}

EL ARCHIVO LISTACOLA:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
///////////////////////////LISTA QUE MANIPULA A LOS PUNTEROSY METODOS /////////////
 
class ListaCola{
    //////PUNTEROS
    public NodoListaCola Primero,Ultimo,Nuevo,Aux,Pos,Ant;
 
    //////constructor
    public ListaCola(){
        Primero = Ultimo = Nuevo = Aux = Pos = Ant = null;
    }
    ////////////////////////INSERTAR COLA//////////
    public void insertarCola(Object dato){
        if(Primero==null){//////////1 caso(lista vacia)
        Primero = new NodoListaCola(dato);
        Ultimo = Primero;
        }
        else{
            Nuevo = new NodoListaCola(Ultimo, dato);
            Ultimo.Der = Nuevo;
            Ultimo = Nuevo;
        }despliegaListaCola();
    }
 
    ///////////////ELIMINAR COLA//////////////
    public void eliminarCola(){
        if(Primero==null){
            System.out.println ("lista vacia");
        }
        else{
        ///hacer cuatro casos
                if(Primero==Ultimo){//// 1 caso
                    Primero=Ultimo=null;
                }
                else {//2caso
                    Primero=Primero.Der;
                    Primero.Izq=null;
                }
 
        }despliegaListaCola();
    }
 
    ////////////////////DESPLEGAR LISTA DOBLE////////////////
    public  void despliegaListaCola(){
        Aux = Primero;
        System.out.println ("#########   LISTA COMPLETA   ###########");
        while (Aux != null) {
            System.out.println (Aux.info);
            Aux = Aux.Der;
        }
        System.out.println ("########################################");
    }
 
 
 
}

Y POR ULTIMO EL APPLISTACOLA:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
class AppListaCola{
    public static void main(String args[]){
        ListaCola lista = new ListaCola();
        Integer DatoB,DatoI;
        int opcion;
 
        //Inicializacion del teclado
        Scanner Teclado = new Scanner(System.in);
        do{
            System.out.println ("1) INSERTAR COLA");
            System.out.println ("2) ELIMINAR COLA");
            System.out.println ("3) DESPLEGAR LISTA");
            System.out.println ("4) SALIR");
            opcion = Teclado.nextInt();
            switch (opcion) {
                case 1: System.out.println ("Que dato quieres insertar en la Lista:  ");
                        DatoI = new Integer(Teclado.nextInt());
                        lista.insertarCola(DatoI);
                        break;
                case 2: lista.eliminarCola();
                        break;
                case 3: lista.despliegaListaCola();
                        break;
                case 4: System.out.println ("BYE....");
                        break;
 
                default :System.out.println ("\topcion no valida intenta de nuevo\n");
            }
        }while (opcion != 4);
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar