定义结点类
public class PolyNode {
/**
* 定义结点系数域
*/
private int coef;
/**
* 定义结点指数域
*/
private int exp;
/**
* 定义结点后继引用域
*/
private PolyNode next;
/**
* 无参数构造器
* 构造空结点
*/
public PolyNode() {
this.next = null;
}
/**
* 有参数构造器
* 初始化系数、指数
* @param coef
* @param exp
*/
public PolyNode(int coef, int exp) {
super();
this.coef = coef;
this.exp = exp;
}
public int getCoef() {
return coef;
}
public void setCoef(int coef) {
this.coef = coef;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public PolyNode getNext() {
return next;
}
public void setNext(PolyNode next) {
this.next = next;
}
}
对应单链表的实现
public class PolynomialList {
/**
* 头引用
*/
protected PolyNode first;
/**
* 尾插法实现构造器
* @param initialList
*/
public PolynomialList(String[] initialList) {
//头引用初始化为头结点
first = new PolyNode();
//初始化尾引用,实现未插入
PolyNode rear = first;
for (int i = 0; i
关注
打赏
热门博文
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法
- 【Java】IDEA编译Java项目报错 java: 找不到符号 的解决方法