Question

Structure struct Node int Manth; // Mont h double dAvg: 1/ Average struct Node pNext // with, the linked İist 3hown above the

Name Example Structure typedef struct Node f With the 11nked list shown above the function will return 3 given that the avera

Structure struct Node int Manth; // Mont h double dAvg: 1/ Average struct Node pNext // with, the linked İist 3hown above the function will return gven that the average is 3.8 Ptr to next -Node; Ret (3,3.8) (4,2.5) (20pts)( Recursive function) Show the code for a function that receives a pointer to the head of an ordered singly linked list that uses the structure in the top left. The function will return the pointer node that shows the highest average. 4、 5. (5pts) Show the trace to your program for problem 6
Name Example Structure typedef struct Node f With the 11nked list shown above the function will return 3 given that the average is 3.8 int iMonth; Month double dAve struct Nade phext; Ptr to next / Average 1 Node pRet 2,2.7 (5,2.0) 3.3.8) 4,2.5) 4. (20pts) (Recursive function) Show the code for a function that receives a pointer to the head of an ordered singly linked list that uses the structure in the top left. The function will return the pointer to the node that shows the highest average.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

4.

// recursive function to return the node with the highest average
Node *highestAvg(Node *head)
{
   if(head == NULL) // check if input node is null, return null
       return NULL;
   else
   {
       Node *highest = highestAvg(head->pNext); // get the highest average for rest of the list
       if((highest != NULL)) //check if highest is not null
       {
           if(highest->dAvg > head->dAvg) //check if average of highest is greater than average of head then return highest
               return highest;
       }

       return head; // return head
   }
}

Add a comment
Know the answer?
Add Answer to:
Structure struct Node int Manth; // Mont h double dAvg: 1/ Average struct Node pNext // with, the linked İist 3hown above the function will return gven that the average is 3.8 Ptr to next -Nod...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following linked list structure called node: struct node { int val; struct node *...

    Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...

  • In C++ Assuming: struct node { int data; node * next; }; and copyList(node * head);...

    In C++ Assuming: struct node { int data; node * next; }; and copyList(node * head); Write a recursive function (copyList(node * head)) that will create a copy of the singly linked list.

  • 13. Given the following structure struct node { struct node *next; int id; }; Write a...

    13. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list as the last node of the linked list struct node *insertLast(stuct node **head, int newId) { } 14. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list after a node with the same id as the input parameter...

  • C++ Consider the following structure of node and linked list. struct Node { int key; Node...

    C++ Consider the following structure of node and linked list. struct Node { int key; Node *next; }; 10 -> 20 -> 30 -> 10 -> 10 -> 50 -> 10 -> NULL What will be the output of following pseudo-code? Consider head is the pointer to the first node of above linked list. Node *walker = head; int count = 0; while(walker!= NULL && count < 3) { if(walker->key == 10) { count = count + 1; } walker...

  • A linked list of integers is built using the following struct: struct node {   int data;...

    A linked list of integers is built using the following struct: struct node {   int data;   struct node *next; }; Define a function named max that returns the maximum integer in a list. The function takes one arguments, a pointer to the head of the list. The function returns an integer, which is the maximum value. If the list is empty, return zero. NOTE: You know nothing about the values in the list. They could all be negative!

  • C programming Write an iterative and recursive version of a function to print out a linked...

    C programming Write an iterative and recursive version of a function to print out a linked list from head to tail and then do the same for printing a linked list from tail to head. Assume a singly linked list in all cases and access only to a head pointer at the time of the function call. struct node; typedef struct node Node; struct node int data; Node next;

  • A linked list is constructed of nodes described by the following structure: struct node{ char data;...

    A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.

  • Write a C++ function to add a node to the beginning of a linked list. Your...

    Write a C++ function to add a node to the beginning of a linked list. Your function takes two arguments - the head of the linked list and the value num to be added. Note that the list may be empty! Your function should modify the head of the linked list to point to the new node, and set the new node to point to the rest of the list (if not empty). Example: Initial Array: 4->2->3, key = 5...

  • C++ Assume that you have a structure Node as follows: struct Node { int value; Node*...

    C++ Assume that you have a structure Node as follows: struct Node { int value; Node* next; Node(int v, Node* n = nullptr) { // constructor value = v; next = n; } }; Question 1 (20 points) Write a function "count" that counts the number of elements in a given linked list. The prototype of this function is as follows: int count_elements(Node*); Question 2 (20 points) Write a function “average" that calculates the average of all the elements in...

  • CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int heig...

    CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT