Using only the local data already supplied in FileSort, perform an insertion sort on the file pointed to by fd. Use lseeks for this; do not try to create any sort of array or list. An array-based version of insertion is supplied for your reference.
Do not modify this code
#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;
}
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("\n");
return 0;
}