Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Collection;
  2. import java.util.LinkedList;
  3.  
  4. public class Pila<E> extends LinkedList<E> {
  5.  
  6.  
  7. //copia los elmentos de otra coleccion
  8. public Pila(Collection< ? extends E> c){
  9. for(E e : c)
  10. empujar(e);
  11. }
  12.  
  13. public Pila(){ super();}
  14.  
  15. public void empujar(E e ){
  16. super.addFirst(e);
  17. }
  18.  
  19. public E remover(){
  20. return super.removeFirst();
  21. }
  22.  
  23. public boolean estaVacia(){
  24. return super.size() == 0;
  25. }
  26.  
  27. public String toString(){
  28. return super.toString();
  29. }
  30. }
  31.  
  32. import java.util.*;
  33.  
  34. public class DemoDePila {
  35. public static void main(String[]args) {
  36. Pila<Integer> p = new Pila<>(Arrays.asList(1, 2, 3));
  37. System.out.println(p);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement