size_t polynomial::get_degree()
{
size_t i;
for (i=capacity-1; i>0; i--)
if (data[i] != 0.0)
return i;
return 0;
}
******* | 0 | [4] ******* | 0 | [3] ******* | 5 | [2] ******* | 9 | [1] ******* | 0 | [0] *******The "capacity" data members for both polynomials should contain the value 5.
size_t count_X(node *head_pointer, int X)
{
node *p;
size_t count = 0;
for (p=head_ptr; p!= NULL; p = p->link())
if (p->data() == X)
count++;
return count;
}
size_t count_X( node *head_ptr, int X)
{
if (head_ptr == NULL)
return 0;
else if (head_ptr->data() == X)
return 1 + count_X(head_ptr->link(), X);
else
return count_X(head_ptr->link(), X);
}
x = 4 y = 9 x = 3 y = 3 3 2 13 4 7
These functions are O(1): constructor, push, pop, top, empty
These finctions are O(n): copy constructor, destructor, operator =, size