47 lines
827 B
Java
47 lines
827 B
Java
package exp8;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
public class MyList<E> {
|
|
private LinkedList<E> list;
|
|
public MyList(){
|
|
list = new LinkedList<>();
|
|
}
|
|
|
|
public void show(){
|
|
System.out.print("[");
|
|
for(E e :list){
|
|
System.out.print(e+",");
|
|
}
|
|
System.out.println("\b]\n");
|
|
}
|
|
|
|
public void push(E elem){
|
|
list.add(elem);
|
|
System.out.println("Push(" + elem +")");
|
|
show();
|
|
}
|
|
|
|
public E pop(){
|
|
E elem = list.removeLast();
|
|
System.out.println("Pop(" + elem +")");
|
|
show();
|
|
return elem;
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
MyList<Integer> list = new MyList<>();
|
|
|
|
list.push(1);
|
|
list.push(2);
|
|
list.push(3);
|
|
|
|
list.pop();
|
|
|
|
list.push(4);
|
|
}
|
|
}
|
|
|
|
|