您的位置:首页 > 其它

【学习心得】-对一维数组增加或删除数据

2009-12-05 11:07 405 查看
class TT_2
{
//set the value to save the length of runtiming LinerArray;
private int num;
//set the name of the String Array;
private String[] data;

//set the LinerArray's size;
public TT_2(int s)
{
//the part of allowing errors;
if(s <= 0)
s = 10;
//the part of setting;
data = new String[s];
num = 0;
}

//Judge Full;
public boolean IsFull()
{
if(num >= data.length)
return true;
return false;
}

//Judge Empty;
public boolean IsEmpty()
{
if(num == 0)
return true;
return false;
}

//Insert a value;
public void Insert(String value,int pos)
{
if(!IsFull() && (pos >= 0 && pos <= num))
{
for(int i = num - 1;i >= pos;i--)
data[i + 1] = data[i];
data[pos] = value;
num++;
}
}

//Delte a vlaue;
public void Delte(String value,int pos)
{
if(!IsEmpty() && (pos >= 0 && pos <= num - 1))
{
for(int i = pos;i <= num - 1;i++)
data[i] = data[i + 1];
num--;
}
}

//Disply the Array;
public void PrintA()
{
for(int i = 0;i < num;i++)
System.out.print(data[i] + "/t");
System.out.println();
System.out.println();
System.out.println("The programming is end!");
}

//Main method;
public static void main(String[] args)
{
TT_2 T = new TT_2(10);

T.Insert("A",0);
T.Insert("B",0);
T.Insert("C",0);

T.PrintA();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐