Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
2
Indexable
Never
    // private helper methods
    // 0 represents empty pin
    private int getTopSize(Rod rod) {
        int size = 0;
        for(int i = 0; i < noOfDisks; i++){
            if(board[rod.getIndex()][i] == 0){
                if(i > 0){
                    size = board[rod.getIndex()][i-1];
                    break;
                }
                break;
            }
            else
                size = -1;
        }
        
        if(size == -1){
            return 1;
        }
        else if(size > 0){
            return size;
        }
        return 0;
    }

    // -1 represents empty rod
    private int getTopIndex(Rod rod) {
        int indx = -1;
        for(int i = 0; i < noOfDisks; i++){
            if(board[rod.getIndex()][i] == 0){
                indx = i;
                break;
            }
        }
        if(indx == 0){
            return 0;
        }
        else if(indx > -1){
            return indx;
        }
        else{
            return noOfDisks;
        }
    }