1. 程式人生 > >java數據結構 - 數組使用的代碼

java數據結構 - 數組使用的代碼

數據結構 else if ror etl int 研發 union true als

在研發過程中,將開發過程比較好的內容珍藏起來,下面內容段是關於java數據結構 - 數組使用的內容,希望能對大夥有較大用。

public class Array {
    private int[]Array;
    private int ArraySize;
    private int ArrayLength;
    private void GetArray(){
        Array = new int[ArraySize];
        if(Array == null)
            System.out.println("Memory Allocation Error");
    }
    public Array(int size){
        if(size <= 0)
            System.out.println("Invalid Array Size");
        else{
            ArraySize = size;
            ArrayLength = 0;
            GetArray();
        }
    }
    public int GetLength(){
        return ArrayLength;
    }
    public int GetNode(int i){
        return(i<0||i>ArrayLength)?null:Array[i];
    }
    public int Find(int x){
        for(int i=0; i<ArrayLength; i++)
            if(Array[i] == x)return i;
        return -1;
    }
    public boolean Insert(int x,int i){
        if(ArrayLength == ArraySize){
            System.out.println("overflow");
            return false;
        }
        else if(i<0 || i>ArrayLength){
            System.out.println("position error");
            return false;
        }
        else
        {
            for(int j=ArrayLength-1; j>=i; j--)
                return true;
        }
    }
    public boolean Remove(int i){
        if(ArrayLength == 0){
            System.out.println("Array Is Empty");
            return false;
        }
        else if(i<0 || i>ArrayLength-1){
            System.out.println("position error");
            return false;
        }
        else
        {
            for(int j=i; j<ArrayLength-1; j++)
            ArrayLength--;
            return true;
        }
    }
    public void Union(Array a,Array b){
        int n = a.GetLength();
        int m = b.GetLength();
        for(int i=0; i<m; i++){
                n++;
            }
        }
    }
    public void Intersection(Array a,Array b){
        int m = b.GetLength();
        int i = 0;
        while(i<m){
                m--;
            }
        }
    }
}

java數據結構 - 數組使用的代碼