Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pila;
- import java.util.Scanner;
- public class Menu {
- public static void main( String[] args ){
- Scanner teclado = new Scanner( System.in );
- int opcion = 0;
- Pila pila = null;
- while( opcion != 7 ){
- System.out.println( "\n1. Crear Pila" );
- System.out.println( "2. Insertar Elemento");
- System.out.println( "3. Eliminar Elemento" );
- System.out.println( "4. Modificar Elemento" );
- System.out.println( "5. Consultar Elemento" );
- System.out.println( "6. Imprimir" );
- System.out.println( "7. Salir" );
- System.out.print( "Opcion > ");
- opcion = teclado.nextInt();
- switch( opcion ){
- case 1:
- if ( pila == null ){
- System.out.print( "Ingrese tamano Pila: " );
- int tam = teclado.nextInt();
- pila = new Pila( tam );
- System.out.println( "Pila Creada!" );
- }else{
- System.out.println( "Pila ya creada" );
- }
- break;
- case 2:
- if ( pila != null ){
- System.out.print( "Ingrese elemento a insertar: " );
- int elemento = teclado.nextInt();
- pila.insertar( elemento );
- }else{
- System.out.println( "> No Hay Pila <" );
- }
- break;
- case 3:
- if ( pila != null ){
- System.out.print( "Ingrese elemento a eliminar: " );
- int elemento = teclado.nextInt();
- pila.eliminar( elemento );
- }else{
- System.out.println( "> No Hay Pila <" );
- }
- break;
- case 4:
- if ( pila != null ){
- System.out.print( "Ingrese elemento a cambiar: " );
- int valor = teclado.nextInt();
- System.out.print( "Ingrese nuevo valor: " );
- int nuevoValor = teclado.nextInt();
- pila.modificar( valor, nuevoValor );
- }else{
- System.out.println( "> No Hay Pila <" );
- }
- break;
- case 5:
- if ( pila != null ){
- System.out.print( "Ingrese posicion a consultar: " );
- int posicion = teclado.nextInt();
- pila.consultar( posicion );
- }else{
- System.out.println( "> No Hay Pila <" );
- }
- break;
- case 6:
- if ( pila != null )
- pila.imprimir();
- else
- System.out.println( "> No Hay Pila <" );
- break;
- }
- }
- System.exit( 0 );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement