Stair case traversal search

 import java.util.*;


class stairs{

    public static void main(String[] args) {

       
        int m[][]={{10,20,30,40},
                   {15,25,34,45},
                   {27,29,37,48},
                   {32,33,39,50}};
                   
        int start=m[0][m.length-1],key=37;

        int i=0,j=m[0].length-1,z=1;

        while(start!=key){

            // if(key==start){
            //     System.out.print("key found at position "+i+" "+j);
            //     z--;
            //     break;
            // }

            if(key<start){
                j--;
                start=m[i][j];
            }
            else{
                i++;
                start=m[i][j];
            }




        }

        System.out.print("key found at position "+i+" "+j);
    }




}

Comments

Popular posts from this blog

Convert first letter to capital letter in java

Time conversion into IST