Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 比较用链表表示的两个数字_Java_Performance_Recursion_Linked List - Fatal编程技术网

Java 比较用链表表示的两个数字

Java 比较用链表表示的两个数字,java,performance,recursion,linked-list,Java,Performance,Recursion,Linked List,我试图解决一个问题,一个完整的正数表示为一个单向链表,其中最低有效位是头节点 例如,数字1234表示为:4->3->2->1->null 我正试图创建一个递归算法,但恐怕遇到了一些麻烦。如果您能看一看并为我指引正确的方向,我将不胜感激: public int compareTo(BigNumber其他){ 字符串thistr=toString(); 字符串otherStr=other.toString(); if(thistr.length()>otherStr.length()) 返回1; i

我试图解决一个问题,一个完整的正数表示为一个单向链表,其中最低有效位是头节点

例如,数字1234表示为:4->3->2->1->null

我正试图创建一个递归算法,但恐怕遇到了一些麻烦。如果您能看一看并为我指引正确的方向,我将不胜感激:

public int compareTo(BigNumber其他){
字符串thistr=toString();
字符串otherStr=other.toString();
if(thistr.length()>otherStr.length())
返回1;
if(thistr.length()ptr2.getValue())
ret=1;
else if(ptr1.getValue()
我在长度相等的情况下遇到了麻烦。我想创建一个递归,首先转到最后一个节点(最重要的数字),并向后检查节点

问题是函数必须有一个返回值,如果这两个值相等,则返回0,在最后一次迭代之前,没有进一步的迭代移动到节点


我很想听听你的想法,谢谢

在这一行中,您立即返回(仅基于最高有效位):


相反,您必须仅在结果不同于0时返回,否则请检查下一位。

在此行中,您将立即返回(仅基于最高有效位):


相反,如果结果不同于0,则必须返回,否则请检查下一个数字。

Brilliant,伙计!明亮的太棒了,伙计!明亮的
return compareTo(ptr1.getNext(), ptr2.getNext());