Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is a function read And Sort which is supposed to read and sort ints from a given file. The function returns an array of
Below is a function read And Sort which is supposed to read and sort ints from a given file. The function returns an array of the elements and stores into size the number of elements read in. int *readAndsort(File *in_File, int *size){ int *SortArray = (integral*) malloc (sizeof (int)) while(fscanf (in_file, " a", &newData) = 0){ (*size)++: sort Array = (int*) realloc(sortArray, size *sizeof(int)): sortArray (size)-1) = newData: for(i = 1: i 0: j--) { if (arr[j - 1] > arr[j]){ arr[j] = arr (j - 1]: arr [j 1] = arr[j];} } } } return *sortArray: } Identify at least 3 errors in the code (compile time, run time, and logic errors). In addition, this code runs in O(n^3). Identify a specific simple change that would allow it to run in O(n^2)
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