243 |
|
} |
244 |
|
|
245 |
|
return p; |
246 |
+ |
} |
247 |
+ |
|
248 |
+ |
template<typename ElemType> |
249 |
+ |
Polynomial<ElemType> operator *(const Polynomial<ElemType>& p, const ElemType v) { |
250 |
+ |
typename Polynomial<ElemType>::const_iterator i; |
251 |
+ |
Polynomial<ElemType> result; |
252 |
+ |
|
253 |
+ |
for (i = p.begin(); i !=p.end(); ++i) { |
254 |
+ |
result.addCoefficient( i->first , i->second * v); |
255 |
+ |
} |
256 |
+ |
|
257 |
+ |
return result; |
258 |
|
} |
259 |
|
|
260 |
+ |
template<typename ElemType> |
261 |
+ |
Polynomial<ElemType> operator *( const ElemType v, const Polynomial<ElemType>& p) { |
262 |
+ |
typename Polynomial<ElemType>::const_iterator i; |
263 |
+ |
Polynomial<ElemType> result; |
264 |
+ |
|
265 |
+ |
for (i = p.begin(); i !=p.end(); ++i) { |
266 |
+ |
result.addCoefficient( i->first , i->second * v); |
267 |
+ |
} |
268 |
+ |
|
269 |
+ |
return result; |
270 |
+ |
} |
271 |
+ |
|
272 |
|
/** |
273 |
|
* Generates and returns the sum of two given Polynomials. |
274 |
|
* @param p1 the first polynomial |