Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FileSort(int fd) {
- size_t ndx, limit;
- int toInsert, temp;
- limit = 0;
- lseek(fd, 0, SEEK_SET);
- while(read(fd, &toInsert, sizeof(int)))
- {
- limit++;
- }
- while(ndx = --limit)
- {
- lseek(fd,limit*sizeof(int),SEEK_SET);
- read(fd,&toInsert, sizeof(int));
- while(ndx-- >= 0)
- {
- lseek(fd, -2, SEEK_CUR);
- read(fd, &temp, sizeof(int));
- if(temp > toInsert)
- {
- lseek(fd, ndx*sizeof(int), SEEK_SET);
- write(fd, &toInsert, sizeof(int));
- lseek(fd,limit*sizeof(int),SEEK_SET);
- write(fd, &temp, sizeof(int));
- toInsert = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement