?? linlist.java
字號:
public class LinList implements List {
Node head;
Node current;
int size;
LinList(){
head = current = new Node(null);
}
public void index(int i) throws Exception{
if(i < -1 || i > size - 1){
throw new Exception("參數(shù)錯誤!");
}
if(i == -1) return;
current = head.next;
int j = 0;
while((current != null) && j < i){
current=current.next;
j ++;
}
}
public void insert(int i,Object obj) throws Exception{
if(i < 0 || i > size){
throw new Exception("參數(shù)錯誤!");
}
index(i - 1);
current.setNext(new Node(obj,current.next));
size ++;
}
public Object delete(int i) throws Exception{
if(size == 0){
throw new Exception("鏈表已空無元素可刪!");
}
if(i < 0 || i > size - 1){
throw new Exception("參數(shù)錯誤!");
}
index(i - 1);
Object obj = current.next.getElement();
current.setNext(current.next.next);
size --;
return obj;
}
public int size(){
return size;
}
public boolean isEmpty(){
return size == 0;
}
public Object getData(int i) throws Exception{
if(i < -1 || i > size - 1){
throw new Exception("參數(shù)錯誤!");
}
index(i);
return current.getElement();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -