Java 此方法必须返回Object类型的结果 包链接列表; 公共类链接列表{ 公共类节点{ 对象数据; 节点下一步; //节点构造函数 节点(对象数据){ 这个数据=数据; } //吸气剂 对象getdata(){ 返回此.data; } 节点getnext(){ 把这个还给我,下一个; } //塞特 void setnext(节点n){ this.next=n; } } 节点头=null; int size=0; //LinkedList的构造函数 公共链接列表(){}; //返回大小 int size(){ 返回大小; } //返回列表是否为空 布尔isEmpty(){ 如果(大小!=0){ 返回false; } 返回true; } 对象优先(){ 返回header.getdata(); } 最后一个对象(整数大小){ 节点c; 对于(int i=0;i
而言,问题在于Last()并不总是返回值,即使它声称返回值。每个代码路径都必须返回一个值Java 此方法必须返回Object类型的结果 包链接列表; 公共类链接列表{ 公共类节点{ 对象数据; 节点下一步; //节点构造函数 节点(对象数据){ 这个数据=数据; } //吸气剂 对象getdata(){ 返回此.data; } 节点getnext(){ 把这个还给我,下一个; } //塞特 void setnext(节点n){ this.next=n; } } 节点头=null; int size=0; //LinkedList的构造函数 公共链接列表(){}; //返回大小 int size(){ 返回大小; } //返回列表是否为空 布尔isEmpty(){ 如果(大小!=0){ 返回false; } 返回true; } 对象优先(){ 返回header.getdata(); } 最后一个对象(整数大小){ 节点c; 对于(int i=0;i,java,compiler-errors,linked-list,Java,Compiler Errors,Linked List,而言,问题在于Last()并不总是返回值,即使它声称返回值。每个代码路径都必须返回一个值 package LinkedList; public class LinkedList { public class Node { Object data; Node next; //Constructor of Node Node(Object data){ this.data = data; } //getter Object
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;
}
}
}
}
最后一个对象(整数大小){
节点c;
对于(int i=0;i而言,问题在于Last()并不总是返回值,即使它声称返回值。每个代码路径都必须返回一个值
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;
}
}
}
}
最后一个对象(整数大小){
节点c;
对于(int i=0;i您必须在for
循环之外有一个return语句。只有在执行循环并且满足条件时,您拥有的语句才会运行
如果循环之外没有可返回的内容,请添加return null;
作为最后一条语句。您必须在for
循环之外有一条return语句。只有在执行循环且满足条件时,您拥有的语句才会运行
如果循环之外没有可返回的内容,则添加returnnull;
作为最后一条语句