[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/open-source-backup/algo/master/java/05_array/Array.java [Back]  [Original]

package array;

/**
 * 1) 
 * 2int
 *
 * Author: Zheng
 * modify: xing
 */
public class Array {
    //data
    public int data[];
    //
    private int n;
    //
    private int count;

    //
    public Array(int capacity){
        this.data = new int[capacity];
        this.n = capacity;
        this.count=0;//0
    }

    //
    public int find(int index){
        if (index=count) return -1;
        return data[index];
    }

    //:
    public boolean insert(int index, int value){
        // 

        //if (index == count && count == 0) {
        //    data[index] = value;
        //    ++count;
        //    return true;
        //}

        // 
        if (count == n) {
            System.out.println("");
            return false;
        }
        // count
        // 
        if (index < 0||index > count ) {
            System.out.println("");
            return false;
        }
        // 
        for( int i = count; i > index; --i){
            data[i] = data[i - 1];
        }
        data[index] = value;
        ++count;
        return true;
    }
    //
    public boolean delete(int index){
        if (index=count) return false;
        //
        for (int i=index+1; i

Web Proxy Viewer  |  New URL  |  Original Page