1.知识储备
2.代码实现:
package Stack;
import java.util.Iterator;
public class Stack<T> implements Iterable<T>{
//记录首节点
private Node head;
//记录元素个数
private int N;
private class Node{
public T item;
public Node next;
public Node(T item,Node next) {
// TODO Auto-generated constructor stub
this.item=item;
this.next=next;
}
}
public Stack() {
// TODO Auto-generated constructor stub
this.head=new Node(null, null); //初始化头节点
this.N=0;