fix my code do not modify main #include #include #include /* void InsertSort(int
ID: 3557195 • Letter: F
Question
fix my code do not modify main #include #include #include /* void InsertSort(int vals[], int size) { int ndx, insNdx, toInsert; for (ndx = 1; ndx < size; ndx++) { toInsert = vals[insNdx = ndx]; while (insNdx > 0 && toInsert < vals[insNdx-1]) { vals[insNdx] = vals[insNdx-1]; insNdx--; } vals[insNdx] = toInsert; } } */ void InsertSort(int fd) { size_t ndx, limit; int toInsert, temp; for (ndx = 1; ndx < lseek(fd, 0, SEEK_END); ndx++) { lseek(fd,ndx, SEEK_SET); read(fd, &toInsert, sizeof(int)); if(!(ndx % sizeof(int))) { lseek(fd, ndx - sizeof(int), SEEK_SET); read(fd, &temp, sizeof(int)); limit = ndx; while (limit / sizeof(int) > 0 && toInsert < temp) { lseek(fd, limit - sizeof(int), SEEK_SET); read(fd, &temp, sizeof(int)); lseek(fd, limit, SEEK_SET); write(fd, &temp, sizeof(int)); limit -= sizeof(int); } lseek(fd, limit, SEEK_SET); write(fd, &toInsert, sizeof(int)); } } } int main() { int fd, data; fd = open("temp.txt", O_CREAT|O_RDWR|O_TRUNC, 0600); while (EOF != scanf("%d", &data)) write(fd, &data, sizeof(int)); InsertSort(fd); lseek(fd, 0, SEEK_SET); while (0 != read(fd, &data, sizeof(int))) printf("%d ", data); printf(" "); return 0; }
Explanation / Answer
/* now your program has to work, please rate my answer *
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.