Advertisement
cesarnascimento

4

Mar 23rd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package EXEMPLO;
  2.  
  3. import java.util.LinkedList;
  4. import java.util.List;
  5.  
  6. import pilha.PilhaEstatica;
  7.  
  8. public class Exemplo {
  9.  
  10.     public static void main(String[] args) {
  11.         LinkedList<Integer> stack = new LinkedList<>();
  12.         LinkedList<Integer> aux = new LinkedList<>();
  13.         Integer removed = null;
  14.        
  15.         stack.push(1);
  16.         stack.push(2);
  17.         stack.push(3);
  18.         stack.push(4);
  19.         stack.push(5);
  20.        
  21.         for(int i = stack.size(); i > 1; i--) {
  22.             aux.push(stack.pop());
  23.         }
  24.        
  25.         // stack = 1
  26.         // aux = 5, 4, 3, 2
  27.        
  28.         removed = stack.pop();
  29.         //stack =
  30.        
  31.        
  32.        
  33.         for(int i = aux.size(); i > 0; i--) {
  34.             stack.push(aux.pop());
  35.         }
  36.        
  37.         // aux =
  38.         // stack = 2, 3, 4, 5
  39.        
  40.        
  41.     /*  Fila fila;
  42.        
  43.         public void push(Node n) {
  44.             fila.enqueue(n);
  45.         }
  46.        
  47.         public Node pop() {
  48.            
  49.             Node removed = null;
  50.             Fila newfila = new Fila();
  51.            
  52.             for(int i = fila.size(); i > 1; i--)
  53.                 newfila.enqueue(fila.dequeue());
  54.              
  55.             removed = fila.dequeue();
  56.            
  57.             fila = newfila;
  58.            
  59.             return removed;
  60.         } */
  61.        
  62.        
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement