LISTAS DOBLEMENTE ENLAZADAS
Publicado por Gabriel Francisco (11 intervenciones) el 11/04/2019 19:28:42
BUENO AMIGOS, NECESITO QUE ME AYUDEN A CORREGIR MI CLASE, AUN ME FALTA TERMINAR, NECESITO LOS METODOS:
AGREGAR INICIO
AGREGAR FINAL
SABER SI ES VACIO
Y MOSTRAR CADA UNO DE LOS METODOS POR SEPARADO
ESTE ES EL CODIGO:
AGREGAR INICIO
AGREGAR FINAL
SABER SI ES VACIO
Y MOSTRAR CADA UNO DE LOS METODOS POR SEPARADO
ESTE ES EL CODIGO:
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
public class ListaDoblementeEnlazada {
private NodoDoble inicio,fin;
public ListaDoblementeEnlazada(){
inicio=fin=null;
}
public boolean estVacia(){
return inicio ==null;
}
public void agregarFinal(String el){
if(!estVacia()){
fin=new NodoDoble(el, null, fin);
fin.Anterior.Siguiente=fin;
}else{
inicio=fin=new NodoDoble(el);
}
}
public void agregarInicio (String el){
if(!estVacia()){
inicio=new NodoDoble(el, inicio, null);
fin.Siguiente.Anterior=inicio;
}else{
inicio=fin=new NodoDoble(el);
}
}
public void mostrarListaInicioFin(){
if(!estVacia()){
String datos="<=>";
NodoDoble auxiliar=inicio;
while (auxiliar!=null){
datos = datos +"["+auxiliar.dato+"]<=>";
auxiliar=auxiliar.Siguiente;
}
System.out.println("Mostrando datos de Inicio a Fin"); }
}
public void mostrarListaFinInicio(){
if(!estVacia()){
String datos="<=>";
NodoDoble auxiliar=fin;
while (auxiliar!=null){
datos = datos +"["+auxiliar.dato+"]<=>";
auxiliar=auxiliar.Anterior;
}
System.out.println("Mostrando datos de FIn a Inicio");
}
}
public class NodoDoble {
private String dato;
NodoDoble Siguiente,Anterior;
public NodoDoble(String el){
this(el,null,null);
}
//Constructor
public NodoDoble (String el, NodoDoble s, NodoDoble a){
dato = el ;
Siguiente = s;
Anterior = a;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
ListaDoblementeEnlazada Milista=new ListaDoblementeEnlazada();
int opcion = 0;
String el = "";
do{
try{
System.out.println(
"1.Agregar un Nodo al Inicio\n "
+ "2.Agregar un Nodo al Final\n"
+ "3.Mostrar la Lista de Inicio a Fin\n"
+ "4.Mostrar la Lista de Fin a Inicio\n"
+ "5. Salir\n"
+ "Elija una opcion:\n ");
opcion=sc.nextInt();
switch (opcion){
case 1:
System.out.println ("Agregando nodo al inicio");
Milista.agregarInicio(el);
break;
case 2:
System.out.println(" Agregando nodo al inicio");
Milista.agregarFinal(el);
break;
case 3:
if(!Milista.estVacia()){
Milista.mostrarListaInicioFin();
}else{
System.out.println("Lista vaci"
+ ""
+ "a, no hay Nodos aun");
}
break;
case 4:
if(!Milista.estVacia()){
Milista.mostrarListaFinInicio();
}else{
System.out.println("No hay Nodos aun, Lista vacia");
}
break;
case 5:
System.out.println("Aplicacion Finalizada");
break;
default:
System.out.println("La opcion no esta en el menu");
break;
}
}catch(NumberFormatException n){
System.out.println("Error");
}
}while(opcion!=5);
}
}
Valora esta pregunta


0