The coefficient type is not assumed to be ordered, so do not require a sign or absolute-value operation beyond the supplied output routine. Parenthesize coefficients to keep negative or compound values unambiguous:
OutPoly(p):
first = true
while p != NIL:
if p.coeff != 0:
if not first: Out.String("+")
Out.String("("); OutT(p.coeff); Out.String(")")
if p.power != 0:
Out.String("*x")
if p.power != 1:
Out.String("^"); Out.Int(p.power)
first = false
p = p.next
if first: OutT(0)For example, the representation in the question can print
(-1)+(1)*x^2, which denotes the same polynomial. If additionally provides ordered-real sign operations, cosmetic suppression of +(-...) and unit coefficients can produce -1+x^2. The generic routine already handles the zero polynomial and preserves the represented value without introducing those extra assumptions. Articles by others on the same topic
There are currently no matching articles.