Write a function to add two polynomials. Do not destroy the input. Use a linked list implementation with a dummy head node. Note: The zero polynomial is represented by an empty list with only the dummy head node.
Format of functions:
Polynomial Add( Polynomial a, Polynomial b );
where Polynomial
is defined as the following:
typedef struct Node *PtrToNode;
struct Node {
int Coefficient;
int Exponent;
PtrToNode Next;
};
typedef PtrToNode Polynomial;
/* Nodes are sorted in decreasing order of exponents.*/
The function Add
is supposed to return a polynomial which is the sum of a
and b
.
Sample program of judge:
#include <stdio.h>
#include <stdlib.h>
typedef struct Node *PtrToNode;
s