宏
应输入“)”(在头文件中有宏的情况)
#define是把其后面的所有用文本替代。所以在的定义宏时要注意是否要加分号(我注意到好像所有的预处理命令,结尾都不加分号)。
#define MAX 1000;
#define BITS 3;
//这是大数阶乘中进位函数的尾节点处理
void m_carry()
{
if(current->data < MAX) //此处编译器会编译成 if(current->data < 1000;)所以会有“应输入‘)’”的错误
return;
else
last = new LinkNode;
current->link = last;
last->data = current->data / MAX;
current->data = current->data % MAX;
}
实习项目问题及解决方法
大数阶乘
程序运行时间过长,当数达到50000需要一分半的运行时间,100000则运行时间达5分钟以上。暂时未想到解决方法。以下是问题代码。
void BigNumber::m_Carry()
{
LinkNode* current = first;
while (current != last)
{
//进位
current->link->data = current->link->data + current->data / MAX;
//求余
current->data = current->data % MAX;
current = current->link;
}
//尾节点处理
loop:if (current->data < MAX)
return;
else
{
last = new LinkNode;
assert(last != nullptr);
current->link = last;
last->data = current->data / MAX;
current->data = current->data % MAX;
current = current->link;
m_Size++;
}
goto loop;
}
void BigNumber::m_Caculate()
{
int num = m_num;
while (num > 2)
{
LinkNode* current = first;
while (current != nullptr)
{
//阶乘
current->data = current->data * (num - 1);
current = current->link;
}
m_Carry(); //进位
num--;
}
}