Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PilaBasica;
- import java.util.ArrayList;
- public class PilaBasica {
- static ArrayList<Integer> PilaBasica = new ArrayList<Integer>();
- //constructor
- PilaBasica(){
- ArrayList<Integer> PilaBasica = new ArrayList<Integer>();
- }
- //metodos
- void agregar (Integer i){
- this.PilaBasica.add(i);
- }
- void quitar(){
- this.PilaBasica.remove(PilaBasica.size()-1);
- }
- Integer cima (){
- Integer cima = this.PilaBasica.size()-1;
- return cima;
- }
- Integer minimo(){
- Integer actual=null;
- Integer minimo=Integer.MAX_VALUE;
- for (int i = 0; i < this.PilaBasica.size()-1; i++) {
- for (int j = 0; j < this.PilaBasica.size(); j++) {
- if (this.PilaBasica.get(i)<PilaBasica.get(j) ){
- actual = this.PilaBasica.get(i);
- if (actual<=minimo) {
- minimo= actual ;
- }
- }
- }
- }
- return minimo;
- }// obtiene y quita el mínimo de la pila
- public static void main(String[] args) {
- PilaBasica pb = new PilaBasica() ;
- pb.agregar(45);
- //kind of toString ;
- for (int i = 0; i <PilaBasica.size() ; i++) {
- System.out.println(PilaBasica.get(i));
- }
- System.out.println( "minimo = "+pb.minimo());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement