Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns new vector with elements shifted right by a given number of positions.
- */
- public Vector shifted(int amount) {
- int shift = 0;
- Vector v = new Vector(length);
- for (int i = 0; i < this.length; i++) {
- if ((i - amount) < 0) {
- shift = (this.length + (i - amount));
- } else {
- shift = i - (this.length - amount);
- }
- v.elements[i] = this.elements[shift];
- }
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement