您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 抽象数据类型的实现复数
#includestdio.h#includemalloc.htypedefstructnode{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;head=(node*)malloc(sizeof(node));head-next=NULL;scanf(%d,&n);for(i=0;in;i++){p=(node*)malloc(sizeof(node));scanf(%d,&p-number);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-number==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!\n);}else{p=head-next;while(p!=NULL){printf(%d,p-number);p=p-next;}printf(\n);}return0;}#includestdio.htypedefstruct{floatc1,c2;}complex;voidoutput(floatx,floaty){if(x==0){if(y==0){printf(0\n);}else{printf(%.gi\n,y);}}else{if(y==0){printf(%.g\n,x);}elseif(y0){printf(%g+%gi\n,x,y);}else{printf(%g%gi\n,x,y);}}}voidadd(floata,floatb,floatc,floatd){complexl;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);scanf(%f%f,&c,&d);add(a,b,c,d);sub(a,b,c,d);mul(a,b,c,d);}
本文标题:抽象数据类型的实现复数
链接地址:https://www.777doc.com/doc-2373504 .html