Question

IN C++ struct elementType{      int integer;      float decimal;    char ch; }; struct nodeType{...

IN C++

struct elementType{

     int integer;

     float decimal;

   char ch;

};

struct nodeType{

   elementType e;

   nodeType* link:

};

Write a member functions that will find the range of values in a singly linked list. The range is returned to the calling function.

PLEASE USE THE STRUCT ABOVE

Homework Answers

Answer #1

struct nodeType* findRange(struct nodeType *head)
{
     struct elementType min;
     struct elementType max;
    struct  nodeType** node= malloc(2 * sizeof(*nodeType));
     min.integer=INT_MAX;
     min.decimal=FLT_MAX;
     min.ch=CHAR_MAX;
      max.integer=INT_MIN;
     max.decimal=FLT_MIN;
     max.ch=CHAR_MIN;
     
     while(head!=NULL)
     {
        // find minimum range
        if(head->e.integer<min.integer)
        {
                min.integer=head->e.integer;
                }
                 
                 if(head->e.decimal<min.decimal)
        {
                min.decimal=head->e.decimal;
                }
                 
                 if(head->e.ch<min.ch)
        {
                min.ch=head->e.ch;
                }
                
                // for maximum
                if(head->e.integer>max.integer)
        {
                max.integer=head->e.integer;
                }
                 
                 if(head->e.decimal>min.decimal)
        {
                max.decimal=head->e.decimal;
                }
                 
                 if(head->e.ch>min.ch)
        {
                max.ch=head->e.ch;
                }
                 head=head->link;
         }
     
     struct nodeType arr[2];
     arr[0]=min;
     arr[1]=max;
     return arr;
        
}
Know the answer?
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
Similar Questions
With the following structures defined: struct monster_struct {       char *name;       int commonality;       int...
With the following structures defined: struct monster_struct {       char *name;       int commonality;       int weight;       struct monster_struct *next; }; typedef struct monster_struct monster; typedef struct monster_list {       monster *head; } Write functions to return the second-most-common monster and the third-lightest monster in the list. Don’t worry about headers. Don’t worry about which way to resolve ties. The list will always have three monsters in it.
Assume that struct Node{ int item; Node*link; }; Write function NodePtr list_search(NodePtr head, int target); The...
Assume that struct Node{ int item; Node*link; }; Write function NodePtr list_search(NodePtr head, int target); The function will search through the linked list that is pointed by head and return a NodePtr that points to the Node that contains target as its item. If there is no such a Node, NULL will be returned. c++
Given the following function prototypes: float asciiAvg(char mystring[], int length); Write the function definition. The asciiAvg...
Given the following function prototypes: float asciiAvg(char mystring[], int length); Write the function definition. The asciiAvg function should return the average of the ascii values for the characters in the array mystring of length characters.
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function overloading. PSEUDOCODE: Declare necessary variables. Create a class with add(int,int) ,add(float,float) as member functions and necessary variable. add(int,int) is used to add two integer values. add(float,float) is used to add two float values. Using object call the required function with corresponding input. Display the output.
C LANGUAGE IMPLEMENTATION - Writing source files implement several functions, declared in student.h, transcript.h and internal.h...
C LANGUAGE IMPLEMENTATION - Writing source files implement several functions, declared in student.h, transcript.h and internal.h (with support from common.h). There are 3 rules: 1. There are three types of students: undergraduate, MEng and PhD. 2. Undergraduates must complete 40 courses, MEng students 5 and PhD students 2. 3. Undergraduate students require a mark of 50 to pass; graduate students need a 65. ----------------Common.h-------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifndef COMMON_H #define COMMON_H /*Portable macros for declaring C functions visible to C++.*/ #ifdef __cplusplus #define...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT