这里写自定义目录标题
package xianxingbiao;
import java.awt.List;
import java.util.Scanner;
public class xianxing {
private Object[] changdu;
private int xianchang;
private int daxiao;
public xianxing(int daxiao)
{
xianchang=0;
this.daxiao=daxiao;
changdu=new Object[daxiao];
}
public void clear()
{
xianchang=0;
}
public boolean isEmpty()
{
return xianchang==0;
}
public int length()
{
return xianchang;
}
public Object get(int i)throws Exception{
if(i<0||i>xianchang-1)
throw new Exception("第"+i+"个元素不存在");
return changdu[i];
}
public void insert(int i,Object x)throws Exception
{
if(xianchang==daxiao)
throw new Exception("顺序表满");
if(i<0||i>xianchang)
throw new Exception("插入位置错误");
for(int j=xianchang;j>i;j--)
changdu[j]=changdu[j--];
changdu[i]=x;
xianchang++;
}
public void remove(int i)throws Exception
{
if(i<0||i>xianchang-1)
throw new Exception("删除位置错误");
for(int j=i;i<xianchang-1;i++)
changdu[j]=changdu[j+1];
xianchang--;
}
public int indexOf(Object x)
{
for(int i=0;i<=xianchang-1;i++)
{
if(changdu[i].equals(x))
return i;
}
return -1;
}
public void display()
{
for(int i=0;i<xianchang-1;i++)
System.out.println(changdu[i]+"");
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
xianxing L=new xianxing(26);
for(int i=0;i<26;i++){
L.insert(i,'a'+i);
}
System.out.println("请输入需要查询元素的位序号:");
int i=new Scanner(System.in).nextInt();
if(i>0&&i<25){
System.out.println("第"+i+"个元素的直接前驱为:"+L.get(i-1));
System.out.println("第"+i+"个元素的直接后继为:"+L.get(i+1));
}
else if(i==0){
System.out.println("第"+i+"个元素的直接前驱不存在");
System.out.println("第"+i+"个元素的直接后继为:"+L.get(i+1));
}
else{
System.out.println("第"+i+"个元素的直接后继不存在");
System.out.println("第"+i+"个元素的直接前驱为:"+L.get(i-1));
}
}
}