实验要求:顺序表类用C++的模板实现算法用流程图和伪代码的形式分别描述并分析算法时间复杂度输入大数据位数以及每一位的数字从高位到低位输出结果位数和每一位的数字从高位到低位。大整数位数不超过1000。输入数据示例如下:3 1 2 3 3位数数值为1235 1 2 3 4 5 5位数数值为12345加法结果输出数据如下:5 1 2 4 6 8 5位数数值为12468乘法结果输出数据如下:7 1 5 1
#include
template
DataType Delete(int i)
{
DataType temp = data[i];
for (int j = i; j < length - 1; j++)
{
data[j] = data[j + 1];
}
length--;
return temp;
}
int Length()
{
return length;
}
DataType Get(int i)
{
return data[i];
}
void Insert(int i, DataType x)
{
for (int j = length - 1; j >= i; j--)
{
data[j + 1] = data[j];
}
data[i] = x;
length++;
}
};
template
template
int main()
{
int n;
cin >> n;
int a[1000];
for (int i = n - 1; i >= 0; i--)
{
cin >> a[i];
}
SeqList
SeqList<int> B(a, n);
SeqList<int> C = Add(A, B);
cout << C.Length() << " ";
for (int i = C.Length() - 1; i >= 0; i--)
{
cout << C.Get(i) << " ";
}
cout << endl;
SeqList<int> D = Mult(A, B);
cout << D.Length() << " ";
for (int i = D.Length() - 1; i >= 0; i--)
{
cout << D.Get(i) << " ";
}
cout << endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/i7uB 著作权归作者所有。请勿转载和采集!