public List<Integer> spiralOrder(int[][] matrix) {
    	
    	if(matrix.length == 0) return new ArrayList<Integer>();
    	
        List<Integer> result = new ArrayList<Integer>();
        
        int m = matrix.length;
        int n = matrix[0].length;
        
        status = new int[m][n];
        
        //init
        Location current = new Location(0, 0, Location.RIGHT);
        result.add(matrix[0][0]);
        
        while(true){
        	current = whereToGo(current, m, n);
        	
        	if(current.direction == Location.STOP){
        		break;
        	}else{
        		result.add(matrix[current.r][current.c]);
        	}
        }
        
        
        return result;
    }