大数乘法
思路
- 以字符串形式读入每一个数
- 将每个字符转化为对应的数字,并以单链表存储
- 每位相乘,将得到的新链表入栈
代码实现
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int length1=0,length2=0;
typedef struct node{
int data;
struct node *next;
}node;
void print(node *p){
while(p->next!=NULL){
p=p->next;
printf("%d",p->data);
}
printf("\n");
}
void dele(node *s){
node *p;
while(s!=NULL){
p=s;
s=s->next;
free(p);
}
}
node *add2(node *first1,node *first2){
int a=0,c=0,d=0,f=0;
node *result=(node *)malloc(sizeof(node));
node *s=result,*end;
result->next=NULL;
while(first1->next!=NULL&&first2->next!=NULL){
first1=first1->next;first2=first2->next;
a=first1->data;c=first2->data;
d=a+c;
if(f!=0)