数据结构c语言版多项式管理,求大神解答

1. 构建实例,简单复杂无所谓。
2. 定义数据的数据结构
3. 采用单链表存放,定义单链表的数据结构;
4. 基本操作至少实现:建立单链表,读入数据;数据读出,查找,插入,删除;
请根据自己选题,设定一个新的操作,例如多项式相加相减,求导

//链式存储实现多项式
#include <stdio.h>
#include <stdlib.h>
typedef struct term *link;
struct term
{
int c; //系数
int e; //指数
link next;
};
typedef struct
{
link head; //头指针
link tail; //尾指针
}*poly_t;

link TERM(int c, int e)
{
link t = malloc(sizeof *t);
t->c = c;
t->e = e;
t->next = NULL;
return t;
}

poly_t poly_init()
{
poly_t p = malloc(sizeof *p);
p->head = p->tail = TERM(0, 0);
return p;
}

void term_read(poly_t p)
{
int i, n;
int c, e;
scanf("%d\n", &n);
for(i = 0; i < n; i++)
{
scanf("%d_%d\n", &c, &e);
p->tail = p->tail->next = TERM(c, e);
}
}

poly_t poly_destory(poly_t p)
{
link t, x;
for(t = p->head; t; free(t), t = x)
x = t->next;
free(p);
return NULL;
}

void poly_show(poly_t p)
{
link t;
if(p->head == p->tail)
return;
for(t = p->head->next; t != p->tail; t = t->next)
{
printf("%dX^%d_%c_", (t->c > 0) ? (t->c) : (-t->c), t->e, (t->next->c > 0) ? '+' : '-');
}
温馨提示:答案为网友推荐,仅供参考
相似回答