考研数据结构与算法之单链表多项式的计算(一)
2014-04-22 20:51
330 查看
销毁链表的时候出了一点问题,现在被卡住了,明天继续。
#include <stdio.h> #include <stdlib.h> #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 typedef int Status; typedef struct { int coef; // 系数 int expn; // 指数 }term,ElemType; typedef struct Polyn { ElemType data; Polyn* next; }Polyn; typedef struct Polyn *PolynList; // 创建一段多项式 Status CreatePolyn(PolynList *P, int n); // 销毁多项式 Status DestroyPolyn(PolynList *P); // 显示多项式 Status PrintPolyn(PolynList P); // 获取链表长度 int PolynLength(PolynList P); // 多项式相加 Status AddPolyn(PolynList *PA, PolynList *PB); // 多项式相剪 Status SubPolyn(PolynList *PA, PolynList *PB); // 多项式相乘 Status MutPolyn(PolynList *PA, PolynList *PB); int num1[10][2] ={1, 23, 2, 1, 4, 6, 5, 1, 9, 100, 11, 1, 12, 1, 13, 2, 18, 1, 45, 2}; int num2[10][2] ={0, 23, 1, 1, 4, 6, 11, 1, 28, 100, 31, 1, 32, 1, 33, 2, 38, 1, 55, 2}; int main(void) { PolynList list1; CreatePolyn(&list1,7); PrintPolyn(list1); printf("%d",PolynLength(list1)); DestroyPolyn(&list1); system("pause"); } Status CreatePolyn(PolynList *P, int n) { PolynList q,s; int i = 0, j = -1; *P = (PolynList)malloc(sizeof(PolynList)); s = *P; while(i<n) { q = (PolynList)malloc(sizeof(PolynList)); q->data.coef = i; q->data.expn = i; s->next = q; s = q; i++; } s->next = NULL; return OK; } Status PrintPolyn(PolynList P) { PolynList q; q = P->next; printf("================================================================================\n"); printf("原式 = "); do { printf(" %dA%d +", q->data.coef, q->data.expn); q = q->next; }while(q->next); printf(" %dA%d;\n", q->data.coef, q->data.expn); printf("================================================================================\n"); return OK; } int PolynLength(PolynList P) { PolynList q = P->next; int i = 1; while(q->next) { q = q->next; i++; } return i; }
相关文章推荐
- 考研数据结构与算法之单链表多项式的计算(三)
- 考研数据结构与算法之单链表多项式的计算(二)
- 数据结构与算法-实验1-多项式的计算:合并同类项、升幂排序、多项式加法、减法、乘法
- 考研数据结构与算法----单链表的创建和读取(1)
- 考研数据结构与算法----单链表的创建和读取(2)
- 单链表的使用——计算多项式加法
- 使用单链表实现多项式计算示例
- 多项式乘法计算
- c# 利用后缀表达式 计算多项式
- 数据结构与算法之单链表(1)
- vijos - P1739计算系数 (多项式计算 + 杨辉三角形 + 快速幂)
- 基于链表:输入若干整数以单链表形式存储起来,然后计算单链表中结点的个数
- 考研数据结构与算法(4)----有头节点和尾节点的链表
- poj 1996多项式计算
- 【数据结构与算法】【时间复杂度】如何计算时间复杂度
- 用递归函数计算厄密多项式
- 一元多项式的相加(单链表的应用)
- 一元多项式加法——单链表实现
- 10.两个单链表相交,计算相交点
- 拉格朗日多项式插值近似计算