0
package LinkedList;
public class LinkedList {
public class Node {
Object data;
Node next;
//Constructor of Node
Node(Object data){
this.data = data;
}
//getter
Object getdata(){
return this.data;
}
Node getnext(){
return this.next;
}
//setter
void setnext(Node n){
this.next = n;
}
}
Node header = null;
int size = 0;
//Constructor of LinkedList
public LinkedList(){};
//return size
int size(){
return size;
}
//return that list is empty or not
boolean isEmpty(){
if (size != 0){
return false;
}
return true;
}
Object first(){
return header.getdata();
}
Object Last(int size){
Node c;
for(int i=0 ;i<size-1 ;i++){
c = header.getnext();
if (i == size-2){
Object returndata = c.getdata();
return returndata;
}
}
}
}
first()
函數在eclipse上沒有任何錯誤。 但在last()
函數,我得到的錯誤是這個方法必須返回一個Object類型的結果。如何解決這個錯誤?此方法必須返回類型結果對象