Programmiertechnik_I/Aufgabe9/Aufgabe9.java
/**
   * This function rotates the values of an array by n and in direction lef/right
   * 
   * @param array the array which should be rotated
   * @param n     the amount of rotations to one side
   * @param left  if true rotate left, if false rotate right
   * @return the new rotated array
   */
This function rotates the values of an array by n and in direction lef/right

@param array the array which should be rotated
@param n     the amount of rotations to one side
@param left  if true rotate left, if false rotate right
@return the new rotated array
This function rotates the values of an array by n and in direction lef / right @param array the array which should be rotated @param n the amount of rotations to one side @param left if true rotate left if false rotate right @return the new rotated array
public int[] rotate(int[] array, int n, boolean left) {
    int[] newArray = arrayCopy(array);
    for (int i = 0; i < array.length; i++) {
      int pos;
      if (left)
        pos = (i + n) % array.length;
      else
        pos = (i + array.length - n) % array.length;
      newArray[i] = array[pos];
    }
    return newArray;
  }
public int [ ] rotate ( int [ ] array , int n , boolean left ) { int [ ] newArray = arrayCopy ( array ) ; for ( int i = 0 ; i < array . length ; i ++ ) { int pos ; if ( left ) pos = ( i + n ) % array . length ; else pos = ( i + array . length - n ) % array . length ; newArray [ i ] = array [ pos ] ; } return newArray ; }
This function rotates the values of an array by n and in direction lef/right
This function rotates the values of an array by n and in direction lef / right
// Create new copy of array // rotate to left or right by n // calculate new position // copy value from old array at pos