Advertisement
Guest User

shift

a guest
May 23rd, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. /**
  2.      * Returns new vector with elements shifted right by a given number of positions.
  3.      */
  4.     public Vector shifted(int amount) {
  5.    
  6.     int shift = 0;
  7.     Vector v = new Vector(length);
  8.    
  9.     for (int i = 0; i < this.length; i++) {
  10.         if ((i - amount) < 0) {
  11.             shift = (this.length + (i - amount));
  12.         } else {
  13.             shift = i - (this.length - amount);
  14.         }
  15.         v.elements[i] = this.elements[shift];
  16.     }
  17.         return v;
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement