作业久调不成功啊,急!!

mazha250 2003-01-01 04:09:32
是一个用链表实现任意长整数相加减的程序,就是不行啊,请各位大虾给看看#include <stdio.h>
struct Node{
int data;
struct Node *pre;
struct Node *next;
}Node,*node;

struct Hnode{
int size;
int num;
struct Node* tail;
struct Node* next;
}Hnode,*hnode;

void Lin(struct Hnode* hnode1)
{
struct Node* node1,*p;
int inum;
char ch;
hnode1=(struct Hnode*) malloc (sizeof(struct Hnode));
hnode1->num=0;
hnode1->next=NULL;
scanf("%d",&inum);
scanf("%c",&ch);
if (inum>0) hnode1->size=0;
else hnode1->size=1;


if (ch!=';')
{
node1=(struct Node*) malloc(sizeof(struct Node));
node1->data=inum;
node1->next=NULL;
node1->pre=NULL;
p=node1;
if (inum>0)
hnode1->size=0;
else hnode1->size=1;
hnode1->num=1;
hnode1->next=node1;
}

while(ch!=';')
{
scanf("%d",&inum);
scanf("%c",&ch);
node1=(struct Node*) malloc(sizeof(struct Node));
node1->data=inum;
node1->next=NULL;
p->next=node1;
node1->pre=p;
p=node1;
hnode1->num=hnode1->num+1;
}
hnode1->tail=p;
};

void Lout(struct Hnode* hnode1)
{
struct Node* p;
p=hnode1->next;
while(p->next)
{
printf("%d",p->data);
printf(",");
p=p->next;
}
};

void Ladd(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
struct Node* p;
struct Node* q;
struct Node* r;
int i=0,cp=0;
p=hnode1->tail;
q=hnode2->tail;
hnode3=new(hnode);

while((i<=hnode1->num) && (i<=hnode2->num))
{
r=new(Node);
r->data=p->data+q->data+cp;
if ((r->data)>10000)
{r->data=r->data-10000;
cp=1;}
else cp=0;
i=i+1;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
q=q->pre;
}

while(i<hnode2->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=q->data;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
q=q->pre;
}

while(i<hnode1->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=p->data;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}

if (cp=1)
{
r=(struct Node*) malloc(sizeof(Node));
r->data=1;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}
};


void Lsub(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
struct Node *p,*q,*r;
int i=0,cp=0;
p=hnode1->tail;
q=hnode2->tail;
hnode3=(struct Hnode*) malloc(sizeof(Hnode));

while((i<=hnode1->num) && (i<=hnode2->num))
{
r=new(Node);
r->data=p->data+q->data-cp;
if (r->data<0)
{r->data=r->data+1000;
cp=1;}
else cp=0;
i=i+1;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
q=q->pre;
}

while(i<hnode2->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=q->data-cp;
cp=0;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
q=q->pre;
}

while(i<hnode1->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=p->data-cp;
cp=0;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}
if (r->data>0)
hnode3->size=1;
else hnode3->size=0;
};

void LAS(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
int i=hnode1->size*hnode2->size;
int j=hnode1->size+hnode2->size;
if((i==0) && (j==1))
Lsub(hnode1,hnode2,hnode3);
else Ladd(hnode1,hnode2,hnode3);
};

void main()
{
struct Node* hnode1,*hnode2,*hnode3;
Lin(hnode1);
Lin(hnode2);
Lin(hnode3);
LAS(hnode1,hnode2,hnode3);
Lout(hnode3);
}

...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mazha250 2003-01-20
  • 打赏
  • 举报
回复
怎么给不了分啊??
mazha250 2003-01-20
  • 打赏
  • 举报
回复
jietie
gagui 2003-01-01
  • 打赏
  • 举报
回复
通不过!!!!
mazha250 2003-01-01
  • 打赏
  • 举报
回复
hnode3= new Hnode;

真的通过了????
w_flyer 2003-01-01
  • 打赏
  • 举报
回复
你是编译不过去,我一帮你通过了!
#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node *pre;
struct Node *next;
};

struct Hnode{
int size;
int num;
struct Node* tail;
struct Node* next;
};

void Lin(struct Hnode* hnode1)
{
struct Node* node1,*p;
int inum;
char ch;
hnode1=(struct Hnode*) malloc (sizeof(struct Hnode));
hnode1->num=0;
hnode1->next=NULL;
scanf("%d",&inum);
scanf("%c",&ch);
if (inum>0) hnode1->size=0;
else hnode1->size=1;


if (ch!=';')
{
node1=(struct Node*) malloc(sizeof(struct Node));
node1->data=inum;
node1->next=NULL;
node1->pre=NULL;
p=node1;
if (inum>0)
hnode1->size=0;
else hnode1->size=1;
hnode1->num=1;
hnode1->next=node1;
}

while(ch!=';')
{
scanf("%d",&inum);
scanf("%c",&ch);
node1=(struct Node*) malloc(sizeof(struct Node));
node1->data=inum;
node1->next=NULL;
p->next=node1;
node1->pre=p;
p=node1;
hnode1->num=hnode1->num+1;
}
hnode1->tail=p;
};

void Lout(struct Hnode* hnode1)
{
struct Node* p;
p=hnode1->next;
while(p->next)
{
printf("%d",p->data);
printf(",");
p=p->next;
}
};

void Ladd(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
struct Node* p;
struct Node* q;
struct Node* r;
int i=0,cp=0;
p=hnode1->tail;
q=hnode2->tail;
hnode3= new Hnode;

while((i<=hnode1->num) && (i<=hnode2->num))
{
r=new Node;
r->data=p->data+q->data+cp;
if ((r->data)>10000)
{r->data=r->data-10000;
cp=1;}
else cp=0;
i=i+1;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
q=q->pre;
}

while(i<hnode2->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=q->data;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
q=q->pre;
}

while(i<hnode1->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=p->data;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}

if (cp=1)
{
r=(struct Node*) malloc(sizeof(Node));
r->data=1;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}
};


void Lsub(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
struct Node *p,*q,*r;
int i=0,cp=0;
p=hnode1->tail;
q=hnode2->tail;
hnode3=(struct Hnode*) malloc(sizeof(Hnode));

while((i<=hnode1->num) && (i<=hnode2->num))
{
r=new(Node);
r->data=p->data+q->data-cp;
if (r->data<0)
{r->data=r->data+1000;
cp=1;}
else cp=0;
i=i+1;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
q=q->pre;
}

while(i<hnode2->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=q->data-cp;
cp=0;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
q=q->pre;
}

while(i<hnode1->num)
{
r=(struct Node*) malloc(sizeof(struct Node));
r->data=p->data-cp;
cp=0;
i++;
r->next=hnode3->next;
hnode3->next=r;
r->next->pre=r;
p=p->pre;
}
if (r->data>0)
hnode3->size=1;
else hnode3->size=0;
};

void LAS(struct Hnode* hnode1,struct Hnode* hnode2,struct Hnode* hnode3)
{
int i=hnode1->size*hnode2->size;
int j=hnode1->size+hnode2->size;
if((i==0) && (j==1))
Lsub(hnode1,hnode2,hnode3);
else Ladd(hnode1,hnode2,hnode3);
};

void main()
{
struct Hnode *hnode1,*hnode2,*hnode3;
Lin(hnode1);
Lin(hnode2);
Lin(hnode3);
LAS(hnode1,hnode2,hnode3);
Lout(hnode3);
}

70,032

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧