链表的高精度*+法;高精度 加法 乘法

本文介绍了一种使用链表实现高精度数值的加法和乘法的方法。通过递归调用`addlist`函数,处理进位和非进位的情况,将两个链表表示的数相加或相乘。在处理过程中,创建新的节点来存储结果,并确保正确处理进位。当计算到最顶层时,返回最终结果链表。
摘要由CSDN通过智能技术生成
Node * addlist(int carry,Node *first, Node *second)
{
if(first == NULL && second == NULL)
return NULL;
struct Node *res = createNode(0);
int value=carry;
value+=(first->data+second->data);
struct Node *more = addlist( value/10,first!=NULL ? first->next:NULL,second!=NULL ? second->next:NULL);
if(more == NULL && value>=10)
{// in the top of this stack a null will return;this is only run on the second layer of the function stack
Node *newTail = createNode(0);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值