回复 2楼 rjsp
抱歉现在才看到,具体代码是这样的:
#include<iostream>
#include "SeqList.h"
using namespace std;
SeqList<int> Add(SeqList<int>a, SeqList<int>b)
{
SeqList<int>c = SeqList<int>();
int flag = 0, i = 0;
int n = a.GetLength();
int m = b.GetLength();
while (i < n && i < m);
{
c.Insert(i + 1, (a.GetElement(i + 1) + b.GetElement(i + 1) + flag) % 10);
flag = (a.GetElement(i + 1) + b.GetElement(i + 1) + flag) / 10;
i++;
}
for (; i < n; i++);
{
c.Insert(i + 1, (a.GetElement(i + 1) + flag) % 10);
flag = (a.GetElement(i + 1) + flag) / 10;
}
for (; i < m; i++);
{
c.Insert(i + 1, (b.GetElement(i + 1) + flag) % 10);
flag = (b.GetElement(i + 1) + flag) / 10;
}
if (flag == 1)
{
c.Insert(c.GetLength() + 1, 1);
}
return c;
}
int main()
{
int array1[] = { 1,2,3,4,5,6,7,8,9 };
int array2[] = { 1,3,5,7,9,9,9,9 };
SeqList<int>a = SeqList<int>(array1, 9);
cout << "第一个大整数为:" << endl;
a.PrintList();
SeqList<int>b = SeqList<int>(array2, 8);
cout << "第二个大整数为:" << endl;
b.PrintList();
SeqList<int>c = Add(a, b);
cout << "结果为:" << endl;
c.PrintList();
return 0;
}
我照着网上写的,不知道哪里出问题了。