/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.trying;

/**
 * @author cwenao
 * @version $Id OperationArray.java, v 0.1 2017-07-11 8:24 cwenao Exp $$
 */
public class OperationArray<E> {

    public int searchOnUnSortArray(E[] array, int len, E key) {
        for (int i =0;i<len;i++) {
            if (array[i] == key) {
                return  i;
            }
        }
        return -1;
    }


    public int insertOnUnSortArray(E[] array, int len, int index,E key) {
        if (index > len - 1) {
            return -1;
        }

        array[index] = key;

        return index + 1;
    }

    public void deleteOnUnSortArray(E[] array, int index,int len) {
        for (int i = index; i < len - 1; i++) {
            array[i] = array[i + 1];
        }
    }

    public int serachOnSortArray(int[] array, int low, int high, int key) {
        if (high < low) {
            return -1;
        }

        int mid = (low + high) / 2;
        if (array[mid] == key) {
            return mid;
        }
        if (array[mid] < key) {
            return serachOnSortArray(array, mid + 1, high, key);
        } else {
            return serachOnSortArray(array, low, mid - 1, key);
        }
    }


    public static void main(String[] args) {
        OperationArray<Integer> operationArray = new OperationArray<>();
        Integer[] array = {1, 2, 3, 5, 4, 6, 7, 8};
        int len = array.length;

        System.out.println(operationArray.searchOnUnSortArray(array, len, 3));

        operationArray.insertOnUnSortArray(array, len, 4, 100);

        System.out.println(operationArray.searchOnUnSortArray(array, len, 100));

        operationArray.deleteOnUnSortArray(array, 4, len);

        System.out.println(operationArray.searchOnUnSortArray(array, len, 100));

        int[] sortedArray = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        int sortedLen = sortedArray.length;
        int low = 0;
        int high = sortedLen - 1;
        System.out.println(operationArray.serachOnSortArray(sortedArray, low, high, 3));

    }

}


@@ -1230,32 +1230,891 @@
        %7D%0A    %7D%0A%0A
+    private int gcd(int index, int size) %7B%0A        if (size == 0) %7B%0A            return index;%0A        %7D%0A        return gcd(size, index %25 size);%0A    %7D%0A%0A    public void rotateArray(int%5B%5D array, int index) %7B%0A        int tmp;%0A        int j;%0A        int k;%0A%0A        for(int i=0; i%3C gcd(index,array.length);i++) %7B%0A            tmp = array%5Bi%5D;%0A            j = i;%0A%0A            while (true) %7B%0A                k = j + index;%0A                if (k %3E= array.length) %7B%0A                    k = k - array.length;%0A                %7D%0A                if (k == i) %7B%0A                    break;%0A                %7D%0A                array%5Bi%5D = array%5Bk%5D;%0A                j = k;%0A            %7D%0A            array%5Bj%5D = tmp;%0A        %7D%0A        printArray(array);%0A    %7D%0A%0A    private void printArray(int%5B%5D array) %7B%0A        for (int x : array) %7B%0A            System.out.println(x);%0A        %7D%0A    %7D
 %0A    public stat
@@ -2224,16 +2224,18 @@
         
+/*
 Integer%5B
@@ -2663,32 +2663,34 @@
 ay, len, 100));%0A
+*/
 %0A        int%5B%5D s
@@ -2734,24 +2734,26 @@
  9%7D;%0A       
+/*
  int sortedL
@@ -2916,24 +2916,77 @@
 , high, 3));
-%0A
+*/%0A        operationArray.rotateArray(sortedArray, 3);
 %0A    %7D%0A%0A%7D%0A%0A

add the rotate array