Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Public Finance

Authors: Harvey S. Rosen

3rd Edition

0256083762, 978-0256083767