这个哪里错了,麻烦大神帮我看看 - 爱问答

(爱问答)

这个哪里错了,麻烦大神帮我看看

//合并两个有序的单链表,合并之后的链表依然有序

public SingleLinkedListhw MergeList(SingleLinkedListhw A,SingleLinkedListhw B) {

if(A.head.next == null && B.head.next == null) {

return null;

}else if(A.head.next == null) {

return B;

}else if(B.head.next == null) {

return A;

}

 

SingleLinkedListhw C = new SingleLinkedListhw();

HeroNodehw cursor1 = A.head.next;

HeroNodehw cursor2 = B.head.next;

 

while(cursor1 != null && cursor2 != null) {

if(cursor1.no <= cursor2.no) {

C.add(cursor1);

cursor1 = cursor1.next;

}else{

C.add(cursor2);

cursor2 = cursor2.next;

}

}

 

while(cursor1 != null) {

C.add(cursor1);

cursor1 = cursor1.next;

}

 

while(cursor2 != null) {

C.add(cursor2);

cursor2 = cursor2.next;

}

 

return C;

 

}


可以在链表最后加两个哨兵(inf)试试

相关标签:大神

下一篇:如何输入char类型

上一篇:GeForceGTX1660

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?