Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is a function read And Sort which is supposed to read and sort ints from a

ID: 3867166 • Letter: B

Question


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).

Explanation / Answer

Answer for the given Question:

Error 1: File reading fscanf will not chec the !=
Error 2: newData is not defined any where in the code.
Error 3: (*size)++ this statement will increment the address not value

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote