Create Polynomial using Linked List

In the representation of a polynomial, there are some terms. Each term has a coefficient and exponent. Now we can define a structure for each node and whenever required we can create such a new node against each term. Therefore the structure definition looks like this:

struct Polynomial
{
  int iCoeff;
  int iExp;
  struct Polynomial *ptrNext;
}
typedef Polynomial PolyNode;

Create Polynomial list:

We know how to append a node at the end of a singly linked list. Now to create a polynomial using a linked list, we need to append the new node at the last of the list.

Alogorithm for Polynomial list:

Algorithm fnCreate_Polynomial(ptrPoly, iCoeff, iExp)
{
  PolyNode *ptrTemp, *ptrNewNode;
  ptrTemp=ptrPoly;
  ptrNewNode=(PolyNode*) malloc(sizeof(PolyNode));
  if(ptrPoly==NULL)
  ptrPoly=ptrNewNode;
  else
 {
   while(ptrTemp->ptrNext!=NULL)
    ptrTemp=ptrTemp->ptrNext;
   ptrTemp->ptrNext=ptrNewNode;
 }
 ptrNewNode->iCoeff=iCoeff;
 ptrTemp->iExp=iExp;
 ptrTemp->ptrNext=NULL;
 return ptrPoly;
}  / End of Algorithm