1. Create a class polynomial to create a linked list that uses class node from task 1 with the following functionalities
a. Insertion. This function takes as an input the size of polynomial. E.g if the size is 6, the polynomial equation is of degree 6. Then you are required to create the appropriate list.
6x6+ 12x3+5
b. Deletion. This function deletes the list of the degree of number passed as a parameter. E.g if the number is 7, it is invalid. If it is 2, it deletes the first 2 degrees and the remaining list is 12x3+5
c. Overload the function of deletion. This function deletes the entire list.
d. Traversal
e. Print equation in the following format
6x6+0x5+0x4+ 12x3+0x2+0x1+5
struct linked_list {
int coefficient;
int power;
char sign
struct linked_list *next;
};
void print(struct linked_list *list) {
if (list) {
std::cout << list-sign << list->coefficient << "x^" << list->power;
print(list->next);
} else {
std::cout << std::endl;
}
}
Comments
Leave a comment