In: Computer Science
Nodes Problems
In C++,
Your objective is to write the definition of the function Maximum() whose header is double Maximum(Node* root) It returns the maximum value from the singly linked list referenced by root. If root is referencing an empty list, the function returns 0.
Part B: Take home Your objective is to write the definition of the following functions the function
EndAppend() whose header is void EndAppend(Node*& data,Node* addon) template It appends the linked list referenced by addon to the end of the linked list referenced by data. For instances, if data = [a, b, c, d, e] and addon = [f, g, h, i, j]; then after the call of the function, data = [a, b, c, d, e, f, g, h, i, j].
the function GreaterThan() whose header is bool GreaterThan(Node* op1,Node* op2). Given that op1 and op2 references doubly linked lists that represent binary numbers, the function returns true if the list referenced by op1 is greater than the list referenced by op2 . For instances, if op1 = [0, 0, 1, 1, 0] and op2 = [1, 0, 0, 1], the function will return false. Do not assume that the lists are the same size.
double Maximum(Node* root){
if(root == NULL) return 0;
double max = root -> data;
while(root != NULL){
if(root->data > max) max =
root->data;
root = root->next;
}
return max;
}
void EndAppend(Node*& data,Node* addon){
if(data == NULL){
data = addon;
return;
}
Node* current = data;
while(current->next != NULL) current =
current->next;
current->next = addon;
}
bool GreaterThan(Node* op1,Node* op2){
int val1 = 0, val2 = 0;
while(op1 != NULL){
val1 = val1*2;
val1 = val1 + op1->data;
op1 = op1->next;
}
while(op2 != NULL){
val2 = val2*2;
val2 = val2 + op2->data;
op2 = op2->next;
}
return val1>val2;
}