SHARE
TWEET

Untitled

a guest Apr 24th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args) throws Exception {
  2.     Pilha a = new Pilha(4);
  3.     a.empilhar(23);
  4.     a.empilhar(52);
  5.     a.empilhar(38);
  6.     a.empilhar(91);
  7.  
  8.     Pilha b = new Pilha(4);
  9.     b.empilhar(91);
  10.     b.empilhar(53);
  11.     b.empilhar(86);
  12.     b.empilhar(42);
  13.  
  14.     Pilha intersec = new Pilha(a.quantosElementos() + b.quantosElementos());
  15.  
  16.     for (int i = a.quantosElementos() - 1; i >= 0; i--) {
  17.         for (int j = b.quantosElementos() - 1; j >= 0; j--) {
  18.             int valA = (int) a.elementoNaPos(i);
  19.             int valB = (int) b.elementoNaPos(j);
  20.  
  21.             if (valA == valB)
  22.                 intersec.empilhar(valA);
  23.         }
  24.     }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top