顺序表链式结构实现多项式相加。参照《数据结构》中的伪代码

2023-11-01

写了一个晚上,只是把多项式相加的实现了。

多项式的销毁也没写完。其中LinkList也没太完全弄明白书里到底是什么意思,数据结构的书太乱了,给的是伪代码也就算了,还不给给全,真是太闹心了。

#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int BOOL;
typedef int Status;

typedef struct {
	float coef;
	int expn;
}term, ElemType;

typedef struct LNode{
	ElemType data;
	struct LNode* next;
}*Link,*Position;

typedef struct {
	Link head,tail;
	int len;
}LinkList;
typedef LinkList polynomial;

Status InitList(LinkList& L);
	// 构造一个空的线型链表L
Position GetHead(LinkList L);
	// 返回线性链表L中头节点的位置
Status SetCurElem(Link& p,ElemType e);
	// 已知p指向线性链表中的一个结点,用e更新p所指的结点中数据元素的值
Position LocateElem(LinkList L,ElemType e,Status (*compare)(ElemType,ElemType));
	// 返回线型链表L中第一个与e满足函数compare()判定关系的元素位置,
	// 若不存在返回NULL
Status MakeNode(Link& p,ElemType e)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

顺序表链式结构实现多项式相加。参照《数据结构》中的伪代码 的相关文章

随机推荐