Okay, so you are given the structure the data is given to you. Your two main options here are use it as is, or convert it to another form for your use, and then convert back.
Either way, it may be useful to break down the problem of adding two polynomials by defining a function, say add-term-to-poly, and then use it in writing add-poly; if you define such a function, add-poly can be as simple as (for example):
- Code: Select all
(defun add-poly (poly1 poly2)
(dolist (term poly1)
(setf ploy2 (add-term-to-poly term poly2)))
You can of course write it in another style if you want.
If you don't convert to another data structure, add-poly should be easily doable in O(m*n) time (with m and n being the lengths of the two polynomials).
As a hint, take a look at FIND and its :KEY argument. Alternatively, you could do add-term-to-poly in a recursive manner (which would work assuming the polynomial is not too long).