package com.choongang;

import java.util.Stack;
import java.util.LinkedList;

public class StackStudy {
	
	public static void main(String[] args){
		//Stack<string> stack = new Stack<string>();
		Stack stack = new Stack();
		
		stack.push("1번");
		stack.push("2번");
		stack.push("3번");
		
		System.out.println(stack.size());//stack 사이즈를 출력해라~
		
		/*//System.out.println(stack.get(0));
		System.out.println(stack.pop());
		System.out.println(stack.isEmpty());
		System.out.println(stack.pop());
		System.out.println(stack.pop());
		System.out.println(stack.isEmpty());*/
		
		/* for 문으로
		 * int size = stack.size();
		for(int i=0;i<size;i++){
			System.out.println(stack.pop());
		}*/
		
		//while 문으로
		while(!stack.isEmpty()){//stack이 비어 있지 않으면 실행 해라
			System.out.println(stack.pop());
		}
		System.out.println("====================");
		
		
		
		//LIFO : Last In First Out - Stack
		//FIFO : First In First Out - Queue
		
		LinkedList<string> link = new LinkedList<string>();
		
		link.offer("사과");
		link.offer("귤");
		
		//link.poll();//Object를 return한다.
		System.out.println(link.peek());
		System.out.println(link.poll());
		System.out.println(link.peek());
		System.out.println(link.poll());
		System.out.println(link.peek());
		System.out.println(link.poll());
		
	}
}



'Java > 2012.04 강좌' 카테고리의 다른 글

15일차 확장 for문 향상된 for문  (0) 2012.04.24
15일차 MapInterface  (0) 2012.04.24
14일차 HashSet,Vector  (0) 2012.04.23
14일차 substring  (0) 2012.04.23
14일차 StringTokenizer  (0) 2012.04.23

+ Recent posts