回 帖 发 新 帖 刷新版面

主题:链表问题

下面这段代码在第二次执行时就会出现问题
one,two three均为有序链表
      case  '7': {
                   bag three;
                   three = one + two;
                 }
                 break;

回复列表 (共2个回复)

沙发

链表的加法可以吗?

板凳

[quote]链表的加法可以吗?[/quote]
加法没问题,第一次执行都是正确的
bag operator + ( bag& fst,  bag& snd)
{
     bag thr;
     if (fst.head != NULL)   thr.addNode ( fst.head,thr);
     if (snd.head != NULL)   thr.addNode ( snd.head,thr);
     return thr;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册