import java.util.Scanner; class Stack { /* * Clase que representa un stack e implementa el push y el pop del stack. Acepta integers como floats */ private int[] stack; private float[] stackf; private int capacidad; private int pointer; public float[] getStackf() { return stackf; } public void setStackf(float[] stackf) { this.stackf = stackf; } public int getPointer() { return pointer; } public void setPointer(int pointer) { this.pointer = pointer; } public int getCapacidad() { return capacidad; } public void setCapacidad(int capacidad) { this.capacidad = capacidad; } public Stack(int capacidad, int[] stack, float[] stackf){ this.capacidad = capacidad; this.stack = stack; this.pointer = capacidad - 1; this.stackf = stackf; } public void push(float number){ if(pointer + 1 == capacidad){ System.out.println("El stack esta a maxima capacidad"); }else{ this.stack[pointer+1] = (int)number; this.stackf[pointer+1] = number; pointer++; } } public void push(int number){ if(pointer + 1 == capacidad){ System.out.println("El stack esta a maxima capacidad"); }else{ this.stack[pointer+1] = number; this.stackf[pointer+1] = (float)number; pointer++; } } public int pop(){ if(pointer - 1 < -1){ System.out.println("Ya no existen datos en el stack"); }else{ pointer--; return this.stack[pointer+1]; } return -1; } public int[] getStack() { return stack; } public void setStack(int[] stack) { this.stack = stack; } public void printStack(){ for(int i=pointer;i>=0;i--){ System.out.println(stackf[i]); } } } public class StackTest{ public static void main(String[] args){ /* * Menu de gestion del stack. * */ int choice = 0; int cantidad; int dato; boolean continuar = true; Scanner in = new Scanner(System.in); System.out.println("Ingrese la cantidad de datos de su stack: "); cantidad = in.nextInt(); int[] datos = new int[cantidad]; float[] datosf = new float[cantidad]; for(int i=0;i