Question

In: Computer Science

Nodes Problems In C++, Your objective is to write the definition of the function Maximum() whose...

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.

Solutions

Expert Solution

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;
}


Related Solutions

answer in c++ , Write the definition of the function NthOccurrence() whose header is int NthOccurrence(Array&...
answer in c++ , Write the definition of the function NthOccurrence() whose header is int NthOccurrence(Array& data,const T& value,int n) template It returns the index of the nth occurrence of value in data. If n is not positive, value appears less than n times in data or data is empty, it returns -1.
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It...
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It returns the amount of times the maximum value of data appears in data. If data is empty, it returns 0. For instance, if data = [7, 1, 4, 9, 6, 7, 7, 3, 2, 6, 9, 5, 9], it will return 3 since 9 appears three times
In objective-C Task: Write a program whose input is a character and a string, and whose...
In objective-C Task: Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is:...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Write the following task in C++1) Write the definition of a function numOccurrences thatsearches...
Write the following task in C++1) Write the definition of a function numOccurrences that searches for a character in a character array and returns the number of times it occurs in the array. The function has three formal parameters: a char array array, an int variable arraySize representing the size of the array, and a character variable letter representing the character to be searched for in the array.2) Assume the array numbers is an int array of size 10 and...
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character argument/ parameter called "phone" and returns a double. When the variable argument phone contains the caracter a or A, print the word Apple and return 1099.99. When phone contains the caracter s or S print the word Samsung and return 999.99. When phone contains anything else, return 0.0.
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the travellingpointer(1stversion) notation to traverse the array. The function has the following prototype. int maximum ( int *p [ ], int n); 2. Implement the function psum( )that is passed an array of n floats and returns a pointer to the sum of such an array. Print the...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
Write a C function that finds and displays the maximum value ina two-dimensional array of...
Write a C function that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 10-row-by-20-column array of integers in main (), and the starting the address of the array should be passed to the function. Modify the function so that it also displays the rows and columns number of the element with the maximum value
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT