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
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;
}
Get Answers For Free
Most questions answered within 1 hours.