您当前的位置: 首页 >  Java

星拱北辰

暂无认证

  • 0浏览

    0关注

    1205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Java】链表求解一元多项式加法

星拱北辰 发布时间:2019-10-01 14:33:24 ,浏览量:0

定义结点类
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             
关注
打赏
1660750074
查看更多评论
0.0528s