package pzhao.com;

import java.util.Iterator;

public class Stack<Item>implements Iterable<Item> {
	private Item[] items;
	private int N;
	private int top;
	public Stack(){
		this(5);
	}
	@SuppressWarnings("unchecked")
	public Stack(int n){
		this.N=n;
		items=(Item[])new Object[N];
	}
	public void push(Item item){
		items[top++]=item;
	}
	
	public Item pop(){
		if(top<=0)return null;
		return items[--top];
	}
	
	public Item peek(){
		return items[top-1];
	}

	@Override
	public Iterator<Item> iterator() {
		// TODO Auto-generated method stub
		return new Iterator<Item>() {

			@Override
			public boolean hasNext() {
				// TODO Auto-generated method stub
				return top>=0;
			}

			@Override
			public Item next() {
				// TODO Auto-generated method stub
				return pop();
			}
		};
	}

	public static void main(String[] args){
		Stack<Integer> stack=new Stack<>(10);
		for(int i=0;i<10;i++){
			stack.push(i);
		}
//		for(int i=0;i<10;i++){
//		System.out.print(stack.pop()+" ");	
//		}
		System.out.print(stack.peek()+" ");	
		Iterator<Integer>iterator=stack.iterator();
		while(iterator.hasNext()){
			System.out.print(iterator.next()+" ");
		}
	}
	
}

@@ -178,9 +178,10 @@
 his(
-5
+10
 );%0A%09
@@ -457,16 +457,173 @@
 p-1%5D;%0A%09%7D
+%0A%09%0A%09public String toString()%7B%0A%09%09StringBuilder sb=new StringBuilder();%0A%09%09for(int i=top-1;i%3E=0;i--)%7B%0A%09%09%09sb.append(items%5Bi%5D+%22 %22);%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D
 %0A%0A%09@Over
@@ -1151,16 +1151,47 @@
 //%09%09%7D%0A%09%09
+System.out.println(stack);%0A%09%09//
 System.o
@@ -1294,17 +1294,19 @@
 ext())%7B%0A
-
 %09
+//
 %09%09System

add size method