您的位置:首页 > 理论基础 > 数据结构算法

java数据结构 - 数组使用的代码

2019-01-28 16:10 387 查看

在研发过程中,将开发过程比较好的内容珍藏起来,下面内容段是关于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--;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数组 数据结构