Demonstration of Polynomial using Linked List
# include
# include
Struct link
{
Char sign; intcoef; int expo;
struct link *next;
};
Typedefstruct link poly; void insertion (poly *); void create_poly (poly *); void display (poly *);
/* Function create a ploynomial list */
voidcreate_poly (poly *start)
{
charch;
staticinti;
printf("\n Input choice n for break: ");
ch = getchar ();
if (ch != 'n')
{
print f("\n Input the sign: %d: ", i+1);
scanf("%c", &start->sign);
printf("\n Input the coefficient value: %d: ", i+1);
scanf("%d", &start->coef);
printf("\n Input the exponent value: %d: ", i+1);
scanf("%d", &start->expo);
}
else
flush(stdin);
i++;
start->next = (poly *) malloc(size of(poly));
create_poly(start->next);
start->next=NULL;
}
/* Display the polynomial */
void display(poly *start)
{
If(start->next != NULL)
{
Printf(" %c", start->sign);
printf(" %d", start->coef);
printf("X^%d", start->expo);
display(start->next);
}
}
/* counting the number of nodes */
Int count poly(poly *start)
{
Lists
If(start->next == NULL)
return 0;
else
}
Return(1+count_poly(start->next));
/* Function main */
void main()
{ poly *head = (poly *) malloc(sizeof(poly));
Create poly(head);
Printf("\n Total nodes = %d \n", count poly(head));
Display (head) ;}
Program: Representation of Polynomial using Linked list