链表长整数加法

这篇博客探讨了如何使用链表来表示和运算长整数,重点在于解决链表形式的长整数相加问题。
摘要由CSDN通过智能技术生成

人做题?
人做题?
人做题?
人做题?
人做题?


#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

struct Listnode{
   
    Listnode *prior;
    Listnode *next;
    int data;
};
int compare(string str1,string str2)
{
   
    int len_a,len_b,i=0,j=0,temp_a,temp_b;
    len_a=str1.size();
    len_b=str2.size();
    if(str1[0]=='-')
    {
   
        i++;
        temp_a=len_a-1;
    }
    else
        temp_a=len_a;
    if(str2[0]=='-')
    {
   
        j++;
        temp_b=len_b-1;
    }
    else
        temp_b=len_b;
    for(;i<len_a,j<len_b;i++,j++)
    {
   
        if(str1[i]>str2[j])
            return 1;
        else if(str1[i]<str2[j])
            return -1;
    }
    return 0;

}

Listnode* create(string str)
{
   
    Listnode *head=new Listnode;
    Listnode *cur=new Listnode;
    cur=head;
    head->data=1;
    int len=str.size();
    for(int i=0;i<len;i++)
    {
   
        if(i==0&&str[i]=='-')
        {
   
            head->data='-1';
        }
        else{
   
            Listnode *p=new Listnode;
            p->data=str[i]-'0';
            cur->next=p;
            p->prior=cur;
            cur=cur->next;
            p->next=NULL;
        }

    }
    return head;
}
Listnode* Add(Listnode *head_a,Listnode *head_b)
{
   
    Listnode *tail_a,*tail_b;
    Listnode *p,*q;
    p=head_a->next;
    q=head_b->next;
    int d;
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值