#include <stdio.h> typedef struct node {float bott; int top; struct node *next; }lnode;
lnode *creat() { lnode *l; float x; int y; lnode *s,*r; l=(lnode*)malloc(sizeof(lnode)); l->next=NULL; printf(" please input the bott and the top,the figure of top must in order:\n"); scanf("%f %d",&x,&y); while(x!=0) {s=(lnode*)malloc(sizeof(lnode)); s->bott=x; s->top=y; s->next=NULL; if(l->next==NULL) {l->next=s; r=s; } else {r->next=s;
r=s; } scanf("%f %d",&x,&y); } return l; }
void plus(lnode *p,lnode *q) { lnode *t,*m; float r; t=p->next; m=q->next;
printf("the result is:\n"); while(t&&m) { if(t->top==m->top) { r=t->bott+m->bott; if(r!=0) { printf("%f,%d\n",r,t->top);t=t->next;m=m->next; } } else if(t->top<m->top) { printf("%f,%d\n",m->bott,m->top); m=m->next; } else if(t->top>m->top) { printf("%f,%d\n",t->bott,t->top); t=t->next; } }
if(t!=NULL) { while(t) { printf("%f,%d\n",t->bott,t->top);t=t->next; } } else if(m!=NULL) { while(m) { printf("%f,%d\n",m->bott,m->top);m=m->next; } } getch();
}
main() { lnode *p,*q;
p= creat();
q= creat();
plus(p, q); }
这个是用C编的,, 你如果要C++的话,, 自己转换一下..