资源描述:
《抽象数据类型的实现复数.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#includetypedefstructnode{intnumber;structnode*next;}node;node*findlast(node*head);node*findlast(node*head){node*last;last=head;while(last->next!=NULL){last=last->next;}returnlast;}intmain(){node*head,*p,*last,*temp;intn,i,num,flag=-1
2、;head=(node*)malloc(sizeof(node));head->next=NULL;scanf("%d",&n);for(i=0;inumber);last=findlast(head);last->next=p;p->next=NULL;}scanf("%d",&num);p=head;temp=p->next;while(1){if(temp->next!=NULL){if(temp->num
3、ber==num){p->next=temp->next;flag++;break;}p=p->next;temp=p->next;}else{if(temp->number==num){p->next=NULL;flag++;}break;}}if(flag==-1){printf("NotFound!");}else{p=head->next;while(p!=NULL){printf("%d",p->number);p=p->next;}printf("");}return0;}#include4、io.h>typedefstruct{floatc1,c2;}complex;voidoutput(floatx,floaty){if(x==0){if(y==0){printf("0");}else{printf("%.gi",y);}}else{if(y==0){printf("%.g",x);}elseif(y>0){printf("%g+%gi",x,y);}else{printf("%g%gi",x,y);}}}voidadd(floata,floatb,floatc,floatd){c
5、omplexl;l.c1=a+c;l.c2=b+d;output(l.c1,l.c2);}voidsub(floata,floatb,floatc,floatd){complexl;l.c1=a-c;l.c2=b-d;output(l.c1,l.c2);}voidmul(floata,floatb,floatc,floatd){complexl;l.c1=a*c-b*d;l.c2=a*d+b*c;output(l.c1,l.c2);}main(){floata,b,c,d;scanf("%f%f",&a,&b);sc
6、anf("%f%f",&c,&d);add(a,b,c,d);sub(a,b,c,d);mul(a,b,c,d);}