Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collection;
- import java.util.LinkedList;
- public class Pila<E> extends LinkedList<E> {
- //copia los elmentos de otra coleccion
- public Pila(Collection< ? extends E> c){
- for(E e : c)
- empujar(e);
- }
- public Pila(){ super();}
- public void empujar(E e ){
- super.addFirst(e);
- }
- public E remover(){
- return super.removeFirst();
- }
- public boolean estaVacia(){
- return super.size() == 0;
- }
- public String toString(){
- return super.toString();
- }
- }
- import java.util.*;
- public class DemoDePila {
- public static void main(String[]args) {
- Pila<Integer> p = new Pila<>(Arrays.asList(1, 2, 3));
- System.out.println(p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement