代码方面:
运用数据结构知识,将一个数组分别以字符串和顺序表的形式表现出来。
package First;
public class SequentialList {
public static final int MAX_LENGTH=10;
int length;
int[] data;
public SequentialList()
{
length=0;
data = new int[MAX_LENGTH];
}
public SequentialList(int[] paraArray)
{
data = new int[MAX_LENGTH];
length = paraArray.length;
for(int i=0;i<paraArray.length;i++)
{
data[i] = paraArray[i];
}
}
public String toString()
{
String resultString="";
if(length==0)
{
return "empty";
}
for(int i=0;i<length-1;i++)
{
resultString += data[i]+", ";
}
resultString+=data[length-1];
return resultString;
}
public void reset()
{
length=0;
}
public static void main(String[] args)
{
int[] tempArray={1,4,6,9};
SequentialList tempFirstList=new SequentialList(tempArray);
System.out.println("Initialized, the list is: "+tempFirstList.toString());
System.out.println("Again, the list is: "+tempFirstList);
}
}
单词方面: