多项式计算器代码

上传人:子 文档编号:43392759 上传时间:2018-06-06 格式:DOC 页数:12 大小:16.03KB
返回 下载 相关 举报
多项式计算器代码_第1页
第1页 / 共12页
多项式计算器代码_第2页
第2页 / 共12页
多项式计算器代码_第3页
第3页 / 共12页
多项式计算器代码_第4页
第4页 / 共12页
多项式计算器代码_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《多项式计算器代码》由会员分享,可在线阅读,更多相关《多项式计算器代码(12页珍藏版)》请在金锄头文库上搜索。

1、多项式计算器代码多项式计算器代码#include “stdafx.h“ #include “stdlib.h“ typedef struct node float con; int exp; struct node * next; listnode; listnode * head; listnode * p; listnode * q; listnode * r; listnode * head1; listnode * head2; int head_num = 0; listnode * point2; void input() int j = 0; int exp; float con

2、; head = (listnode *) malloc (sizeof(listnode); head -next = NULL; start: scanf(“%f %d“, if (exp = 0 p = (listnode *) malloc (sizeof (listnode); j+; p -con = con; p -exp = exp; p -next =head -next; head -next = p; goto start; next: head -exp =j; point head_num = head; head_num +; int bubble_sort(lis

3、tnode * myhead) int i,j; listnode * swap; listnode * real_myhead; real_myhead = myhead; int num = myhead -exp; /myhead = myhead -next; if (num = 1 for (i = 0; i next -exp ) next -next-exp ) swap = (listnode *)malloc (sizeof(listnode);swap -exp = myhead -next -exp; swap -con = myhead -next -con;myhea

4、d -next -exp = (myhead-next -next)-exp myhead -next -con = (myhead-next -next)-conmyhead -next -next -exp = swap -expmyhead -next -next -con = swap -confree (swap); myhead =myhead -next;myhead = real_myhead;if (myhead -exp = 0)return 0;p = myhead -next;for (;p -next != NULL;p = p -next )if (p -exp)

5、=(p-next-exp ) swap = p -nextp -next = p -next -nextfree (swap);real_myhead -exp -= 1;/p =p -nextif (p -exp) =(p-next-exp ) swap = p -nextp -next =NULL;real_myhead -exp -= 1;/free(swap);/goto next;return 0;next:return 0;void myprintf(listnode * node)listnode * mynode; mynode = (listnode *)malloc (si

6、zeof(listnode);mynode -con = node -con;mynode -exp = node -exp;if (mynode -con = 1 ) else if (mynode -con = 1) else if (mynode -con = 0) ;else if (mynode -con != 1) else if (mynode -con != 0) /else if (mynode -exp = 0)/printf(“%f“, mynode -con);else printf(“%.2f x%d“,mynode -con ,mynode -exp );free(

7、mynode);void operplus()head1 = point0;head2 = point1;head = (listnode *)malloc(sizeof(listnode);head -exp = head1 -exp + head2 -exphead -next = NULL; if (head1 -exp = 0)goto first_over; p = head1 -next;for (;p -next != NULL;p = p -next )r = (listnode *) malloc (sizeof(listnode);r -con = p -conr -exp

8、 = p -expr -next = head -nexthead -next = r;r = (listnode *) malloc (sizeof(listnode);r -con = p -conr -exp = p -expr -next = head -nexthead -next = r;first_over: if (head -exp = 0)goto second_over;p = head2 -next;for (;p -next != NULL;p = p -next )r = (listnode *) malloc (sizeof(listnode);r -con =

9、p -conr -exp = p -expr -next = head -nexthead -next = r;r = (listnode *) malloc (sizeof(listnode);r -con = p -conr -exp = p -expr -next = head -nexthead -next = r;second_over: bubble_sort(head);bubble_sort(head);void operminus()head1 = point0;head2 = point1;head = (listnode *)malloc(sizeof(listnode)

10、;head -exp = head1 -exp + head2 -exphead -next = NULL;if (head1 -exp = 0)goto first_over;p = head1 -next;for (;p -next != NULL;p = p -next )r = (listnode *) malloc (sizeof(listnode);r -con = p -conr -exp = p -expr -next = head -nexthead -next = r;r = (listnode *) malloc (sizeof(listnode);r -con = p

11、-conr -exp = p -expr -next = head -nexthead -next = r;first_over: if (head -exp = 0)goto second_over;p = head2 -next;for (;p -next != NULL;p = p -next )r = (listnode *) malloc (sizeof(listnode);r -con = -(p -con)r -exp = p -expr -next = head -nexthead -next = r;r = (listnode *) malloc (sizeof(listno

12、de);r -con = -(p -con );r -exp = p -expr -next = head -nexthead -next = r;second_over: bubble_sort(head);bubble_sort(head);int opermul()head1 = point0; head2 = point1; head = (listnode *)malloc(sizeof(listnode);head -next = NULL;head -exp =(head1 -exp ) * (head2 -exp );if (head -exp = 0)return 0;for

13、 (p = head1 -next p -next !=NULL p = p -next )for(q = head2 -next q -next != NULL; q = q -next )r = (listnode *)malloc (sizeof(listnode);r -con = (q -con ) * (p -con );r -exp = (q -exp ) + (p -exp );r -next =head -next;head -next =r;r = (listnode *)malloc (sizeof(listnode);r -con = (q -con ) * (p -c

14、on );r -exp = (q -exp ) + (p -exp );r -next =head -next; head -next =r;r = (listnode *)malloc (sizeof(listnode);r -con = (q -con ) * (p -con );r -exp = (q -exp ) + (p -exp );r -next =head -next;head -next =r;bubble_sort(head);bubble_sort(head);int output(listnode * output_head)if (output_head -exp =

15、 0)printf(“0n“);return 0;p = output_head -next;if (p -con 0)myprintf(p);p = p -next;for(;p -next != NULL; p = p-next )if (p -con 0) printf(“+“);/else if (p -con con 0)printf(“+“);/else if (p -con exp = 0;operdy_head -next = NULL;if (p -exp = 0)return operdy_head;for (p = p -next p -next != NULL p = p-next )r = (listnode *) malloc (sizeof(listnode);r -con = (p -con)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号