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++
For the following questions, use the definitions of the given structure. struct Date {       int yy,...
For the following questions, use the definitions of the given structure. struct Date {       int yy, mm, dd; }; struct Emp {       char EmpName[25];       float Salary;       struct Date hired; }; struct Dep {       struct Emp manager;       struct Emp worker[25];       float Profits; }; Define a struct Date variable called Date1 and initialize it to February 25, 1957, in the correct format. Define a struct Emp variable called Person1 and initialize it to “Roger”, with a salary of $50,000, who was hired...
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.
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void Ge
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void GenerateFromArray(void); /************************************************************************************/ /************************************************************************************/ int main(void) { /* This is the main() program. It should call the functions ScanArray() and GenerateFromArray() */ GenerateFromArray(); system("pause"); return 0; } /*************************************************************************************** Define this function to scan the elements of an array from the given data file "ArrayInp.dat". If the input file is not found, or contains invalid data, the function should return a 0 and print an error message. If the input...
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...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
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.”....