int getK(int k){ if(k >= length){ return k-length; } else if (k < 0){ return k+length; } else{ return k; } }