QUIERO CONVERTIR ESTA PILA EN UNA COLA
Publicado por Roberto Carlos Delgado Ferman (1 intervención) el 29/09/2020 20:08:27
HOLA Y UNA DISCULPA PERO TENGO UN PROBLEMA, QUIERO CONVERTIR ESTA PILA EN UNA COLA CON QUE SOLO ELIMINE EL PRIMER DATO Y NO EL ULTIMO, SIN UTILIZAR PUSH,POP,ETC, AQUI 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Pila
{
public static void main(String[] args) throws IOException
{
BufferedReader bufer = new BufferedReader(new InputStreamReader(System.in));
String teclado;
int pilavec[]= new int [10];
int Op=0,pos=0,band=0;
while(Op!=4)
{
System.out.println("******* M e n u *******");
System.out.println("1.- Insertar");
System.out.println("2.- Eliminar");
System.out.println("3.- Mostrar Pila");
System.out.println("4.- Salir");
System.out.println("Elija una opcion: ");
Op = Integer.parseInt(teclado = bufer.readLine());
switch (Op)
{
case 1:if (band==0)
{
System.out.println("Teclee un numero: " + pos);
pilavec[pos] = Integer.parseInt(teclado = bufer.readLine());
if ((pos<10)&&(band==0))
{
pos++;
if (pos==10)
{
band=1;
}
}
}
else
{
System.out.println("Pila Llena!!");
}
break;
case 2:if (pos>=1)
{
pilavec[pos-1]=0;
System.out.println("Elemento Eliminado");
pos--;
if (pos==0)
{
System.out.println("Pila Vacia");
}
}
else
{
System.out.println("Pila Vacia");
}
band=0;
break;
case 3:for (int x=0; x< pilavec.length; x++)
{
System.out.println(pilavec[x]);
}
System.out.println("Valor de pos: " + pos);
break;
case 4:System.exit(0);
default:System.out.println("Opcion NO valida");
break;
}
}
}
}
Valora esta pregunta


0