Java 用單鏈表實現多項式加減乘

2021-04-20 19:33:30 字數 941 閱讀 4118

用單鏈表來實現多項式的加減乘,除就不做了,**如下

public

class polynomial  else

if (first == null)  else  else

if (current.next == null) 

current = current.next;}}

}public

}public string tostring() 

return sb.tostring();

}// 兩個多項式相加

public polynomial add(polynomial p2) 

current = p2.first;

while (current != null) 

return result;

}// 兩個多項式相減 this- p2

public polynomial substract(polynomial p2) 

current = p2.first;

while (current != null) 

return result;

}/**

*  this * p2

* * @return

*/public polynomial multiply(polynomial p2) 

c1 = c1.next;

c2 = p2.first;

}return result;

}public polynomial divide(polynomial p2) 

public

static

void main(string args) 

}/**

* 單項式

*/class monomial 

public monomial(double c, int i) 

}

用單鏈表實現多項式加,減,乘,簡單微分

include using namespace std struct polynomial 多項式的結構體 typedef polynomial ptrtopoly typedef ptrtopoly list typedef ptrtopoly position 儲存多項式的係數和次數 typed...

單鏈表實現多項式相加

include include struct node void destroypoly struct node poly 釋放實現多項式申請的空間 return struct node createnode int coe,int exp 申請空間存放多項式當前項 struct node crea...

單鏈表實現多項式相加

本程式使用鍊錶實現了兩個多項式的相加。多項式的相加主要是考慮相加項的指數是否相同,如果相同則係數相加,指數不變。本程式當中,實現該過程的思想為,在錄入乙個多項式所有項的係數和指數以後,使用鍊錶思想構造一條單鏈表,記作鍊錶a,結 點儲存項的係數和指數。依照此法,構建第二條多項式鍊錶,記作鍊錶b。這樣準...