Advertisement
LaCaraDeLaVerga

PILABASICA+minimo()//incompleto

May 23rd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package PilaBasica;
  2. import java.util.ArrayList;
  3. public class PilaBasica {
  4.     static ArrayList<Integer> PilaBasica = new ArrayList<Integer>();
  5.     //constructor
  6.     PilaBasica(){
  7.         ArrayList<Integer> PilaBasica = new ArrayList<Integer>();
  8.     }
  9. //metodos
  10.     void agregar (Integer i){
  11.             this.PilaBasica.add(i);
  12.     }
  13.     void quitar(){
  14.         this.PilaBasica.remove(PilaBasica.size()-1);
  15.     }
  16.     Integer cima (){
  17.         Integer cima = this.PilaBasica.size()-1;
  18.         return cima;
  19.     }
  20.     Integer minimo(){
  21.         Integer actual=null;
  22.         Integer minimo=Integer.MAX_VALUE;
  23.         for (int i = 0; i < this.PilaBasica.size()-1; i++) {
  24.             for (int j = 0; j < this.PilaBasica.size(); j++) {
  25.                 if (this.PilaBasica.get(i)<PilaBasica.get(j) ){
  26.                 actual = this.PilaBasica.get(i);
  27.                     if (actual<=minimo) {
  28.                         minimo= actual ;
  29.                     }
  30.                 }
  31.             }  
  32.         }
  33.         return minimo;
  34.     }// obtiene y quita el mínimo de la pila
  35. public static void main(String[] args) {
  36.      PilaBasica pb = new PilaBasica() ;
  37.      pb.agregar(45);
  38. //kind of toString ;
  39.      for (int i = 0; i <PilaBasica.size()  ; i++) {
  40.             System.out.println(PilaBasica.get(i));     
  41.      }
  42.      System.out.println( "minimo = "+pb.minimo());
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement