1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Maurinko [17]
3 years ago
4

You have an array of elements of type double. It must be sorted, but recently, because of a system glitch, the sorting-in-place

mechanism might allow ONE outlier, i.e., your (supposed to be) sorted array might contain one element in a wrong place. The elements in the array are not necessarily distinct. Write a function that takes the pointer to an array and the array’s size (number of elements in the array) as arguments, finds the place the index of the outlier, fixes the array in place (that is puts the outlier to a place it is supposed to be), and returns the old index where the outlier was found. In case there was no outlier, the function should return -1. This is the function’s signature: long long int fix_sorted_array(double* arr, unsigned long n);
Computers and Technology
1 answer:
tangare [24]3 years ago
8 0

Answer:

#include <stdio.h>

int fix_sorted_array(double * arr,unsigned long n){

int i;

int index=-1;

int item;

for(i=1;i<n;i++){

if(arr[i]<arr[i-1]){

index = i;

item = arr[i];

break;

}

}

for(i=index;i>0;i--){

if(arr[i-1]>item){

arr[i] = arr[i-1];

}else{

arr[i] = item;

break;

}

}

return index;

}

void print(double *arr,long s){

int i;

for(i=0;i<s;i++){

printf("%.2f ",arr[i]);

}

printf("\n");

}

int main(void){

double array[7] = {-23.75,20,25.10,-15,37.10,200.12,1000};

printf("array before : ");

print(array,7);

int index = fix_sorted_array(array,7);

printf("\nReturn index : %d\n",index);

printf("array after : ");

print(array,7);

return 0;

}

Explanation:

#include <stdio.h>

int fix_sorted_array(double * arr,unsigned long n){

int i;

int index=-1;

int item;

for(i=1;i<n;i++){

if(arr[i]<arr[i-1]){

index = i;

item = arr[i];

break;

}

}

for(i=index;i>0;i--){

if(arr[i-1]>item){

arr[i] = arr[i-1];

}else{

arr[i] = item;

break;

}

}

return index;

}

void print(double *arr,long s){

int i;

for(i=0;i<s;i++){

printf("%.2f ",arr[i]);

}

printf("\n");

}

int main(void){

double array[7] = {-23.75,20,25.10,-15,37.10,200.12,1000};

printf("array before : ");

print(array,7);

int index = fix_sorted_array(array,7);

printf("\nReturn index : %d\n",index);

printf("array after : ");

print(array,7);

return 0;

}

You might be interested in
PLEASE I NEED HELP WITH THIS I WILL GIVE BRAINLIST!!!!!
Neko [114]
It would be so you like chocolate because there is only two options. Yes or no
8 0
3 years ago
Read 2 more answers
What do these symbols mean in technology
marta [7]

Answer:

1.us dollar which not not allow

2. pause botton

5 0
3 years ago
If we can lock a file, we can solve the race condition problem by locking a file during the check-and-use window, because no oth
yKpoI14uk [10]

Answer:

A file can only be locked out to other users or processes only if it's already open, meaning it's in use as a resource during the time window and therefore it's impossible solving the race condition problem by locking the file during the check-and-use window.

Hence, during the check-and-use process, it's impossible to lock a file.

In conclusion, any lock created can be ignored by the malicious process.

5 0
3 years ago
Obtain the Truth tables to the following Boolean expressions, and prove the solution's in sagamath
nlexa [21]
The answer to your question is b☺️☺️
4 0
3 years ago
What language(s) MUST be used to display a bare-minimum web page?
gogolik [260]
By using HTML. Hopefully thats the answer you are looking for :)
5 0
3 years ago
Read 2 more answers
Other questions:
  • According to many experts how often should files be backed up
    12·1 answer
  • A(n) _____ is essentially a flash-based replacement for an internal hard drive.
    13·1 answer
  • Assuming that data mining approaches are to be used in the following cases, identify whether the task required is supervised or
    12·1 answer
  • Write a main method that prompts the user for an integer between 1 &amp; 20 (inclusive). If the user enters an invalid number, p
    8·1 answer
  • For what tools such as USMT and Treanxition used?
    15·1 answer
  • Describe some ways that you personally use information technologies differently than you did just a few years ago
    11·1 answer
  • How does this happen on brainly????
    12·2 answers
  • An organization is conducting a study to see if hazardous waste sites pose health risks for cancer or other conditions, such as
    12·1 answer
  • Assume that you have implemented a sequence class. Describe the mySequence object (i.e., items with the correct order and the po
    9·1 answer
  • What is professional education? <br><br><br><br><br>Please help me to do this.​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!