Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public static void main(String[] args) throws Exception {
  2. Pilha<Integer> a = new Pilha<Integer>(4);
  3. a.empilhar(10);
  4. a.empilhar(42);
  5. a.empilhar(95);
  6. a.empilhar(78);
  7.  
  8. int maior = Integer.MIN_VALUE;
  9. int menor = Integer.MAX_VALUE;
  10.  
  11. Pilha<Integer> aux = new Pilha<Integer>(4);
  12.  
  13. while (!a.pilhaVazia()) {
  14. int x = a.desempilhar();
  15. if (x > maior)
  16. maior = x;
  17.  
  18. if (x < menor)
  19. menor = x;
  20.  
  21. aux.empilhar(x);
  22. }
  23.  
  24. while (!aux.pilhaVazia()) {
  25. a.empilhar(aux.desempilhar());
  26. }
  27.  
  28. System.out.println("MAIOR: " + maior);
  29. System.out.println("MENOR: " + menor);
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement