Design advantages

An Item structure is designed to represent each Item. And using a single linked list you can connect these terms in series to form a polynomial. At the same time in the design of a single linked list of various basic functions, more use of template to achieve, in the later can have better ductility.

Major problems encountered during implementation:

  • LNK2019 could not resolve the external symbol pipe_server, this symbol is referenced in the function because I do not reference external library, so exclude lib library factor, but this error is really a link problem. The result is that the function calls a function, but the function is only defined, not written. I found the definition but I couldn’t find the implementation

  • Qin Jiushao algorithm to achieve polynomial evaluation problem: find a lot of blogs, have no good use of qin Jiushao algorithm recursive properties of the algorithm, their own recursive method to write an implementation function:

Double fun(LinkNode<Item>* L, double x) const /* It is best to design as a const function to prevent modification of class members and to allow interfacing with const member functions. */ { LinkNode<Item>* p = L, *q; // Double sum = 0;while(p ! = NULL && p->data.exponent == 0) { sum += p->data.ceofficient; p = p->next;if(p == NULL) // Only constant entriesreturn sum;
		}
		if(p ! = NULL&&p->next == NULL && p->data.exponent == 1)return x * p->data.ceofficient+sum;
			q = p;
			while(p ! = NULL) { p->data.exponent--; p = p->next; }return x * (fun(q, x)+sum);
		
	}
Copy the code
  • Newton iteration method for approximate roots: need to be realized with Qin Jiushao algorithm or other evaluation functions. In my design, because the function called the diff() function to differentiate the expression with each iteration, it would result in a nan or other error. Therefore, fun0 is used to represent the original expression and fun1 is the differential of the original expression.
Friend nutow_fun(Polynomial fun0,Polynomial fun1,double X) Double result = x-fun0.value (x)/fun1.value(x); double result = x-fun0.value (x);if (abs(result - x) >= 1e-8)
			return nutow_fun(fun0, fun1, result);
		else
			return result;
	}

	double root_near(double x0)const
	{
		Polynomial fun0(*this);
		Polynomial fun1(this->diff());
		return nutow_fun(fun0, fun1, x0);
	}
Copy the code
  • The design of other related arithmetic calculation functions is not very different from ordinary variable calculation. This time, many template functions are used to complete the basic functions of constructing and outputting single linked lists. In future design, you can use as many function templates as possible to broaden the function’s extensibility. * Full source code link: github.com/Free-Geter/…