标签:cap for stat nbsp sys public ble getc 线性
顺序存储线性表(数组实现)
public class Sqlist { static int [] table; static int n; public Sqlist(int n) { table=new int[n]; this.n=0; } public boolean isEmpty() { return n==0; } public boolean isFull() { return n>=table.length; } public int getcapacity() { return table.length; } public int getlength() { return n; } //ADD public void addElem(int loc,int value) { if(n>=table.length) { System.out.println("数组满了"); } if((loc<1)||(loc>table.length)) { System.out.println("插入位置错误"); } if(loc<=n+1) { for(int i=n-1;i>=loc;i--) { table[i+1]=table[i]; } table[loc-1]=value; n++; System.out.println("插入成功,在第"+loc+"个位置之前插入:"+value); } } //DELETE public int getElem(int i) { if((i<1)||(i>table.length)) { return -1; } else { return table[i-1]; } } }
标签:cap for stat nbsp sys public ble getc 线性
原文地址:https://www.cnblogs.com/Maskisland/p/10048850.html