Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * Interquartile Range Given a sorted singly linked list without a tail ( e . g , head - > 1 - > 2
Interquartile Range
Given a sorted singly linked list without a tail eg head
return the interquartile range of the data set using the slow and fast pointer
approach OR using a methodology that does not iterate over the linked list
twice. You must not iterate over the entire linked list more than once and you
cannot use arrays, vectors, lists or an STL implementation of List ADT in this problem.
Sample Input:
Sample Output:
#include
#include
class Node
public:
int value;
Node next nullptr;
;
Node insertEndNode head, int key
Node temp new Node;
tempvalue key;
ifhead nullptr
head temp;
else
Node curr head;
whilecurrnext nullptr
curr currnext;
currnext temp;
return head;
float interQuartileNode head
float IQR ;
Node Part NULL;
Node Part NULL;
Node Part NULL;
Node Part NULL;
if head headnext headnextnext headnextnextnext
return ;
Loop that moves pointer
whiletrue
ifPart NULL
Part Partnext;
else
Part head;
ifPart NULL
Part Partnextnext;
else
Part headnext;
ifPart NULL
Part Partnextnextnext;
else
Part headnextnext;
ifPart NULL
Part Partnextnextnextnext;
else
Part headnextnextnext;
Breaks loop
ifPart NULL Partnext NULL
break;
When Odd
ifPart NULL
IQR Partvalue Partvalue;
return IQR;
When Even
else
IQR Partvalue PartnextvaluePartvalue Partnextvalue;
return IQR;
int main
Node head new Node;
headvalue ;
headnext new Node;
headnextvalue ;
headnextnext new Node;
headnextnextvalue ;
headnextnextnext new Node;
headnextnextnextvalue ;
headnextnextnextnext new Node;
headnextnextnextnextvalue ;
headnextnextnextnextnext new Node;
headnextnextnextnextnextvalue ;
headnextnextnextnextnext next new Node;
headnextnextnextnextnextnextvalue ;
headnextnextnextnextnext nextnext new Node;
headnextnextnextnextnextnextnextvalue ;
headnextnextnextnextnext nextnextnext new Node;
headnextnextnextnextnextnextnextnextvalue ;
float result interQuartilehead;
std::cout "Interquartile Ranges: std::fixed std::setprecision result std::endl;
return ;
This is my code, it works but when I try certain numbers, it gives me a "Exception has occurred. Segmentation fault"
For example if I try the numbers or It gives the same error but work for and and
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started