JAVA_アナログstack
1914 ワード
package com.kk.Collection;
import java.util.LinkedList;
/**
*
* (LIFO)
*/
public class MyStack {
private LinkedList ll=new LinkedList();
// push, put
public void push(Object o){
ll.addFirst(o);
}
public Object pop(){
return ll.removeFirst();
}
public Object peek(){
return ll.getFirst();
}
public boolean empty(){
return ll.isEmpty();
}
public static void main(String[] args) {
MyStack stack=new MyStack();
stack.push("a");
stack.push("b");
stack.push("c");
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.empty());
}
}