Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. void FileSort(int fd) {
  2. size_t ndx, limit;
  3. int toInsert, temp;
  4.  
  5. limit = 0;
  6. lseek(fd, 0, SEEK_SET);
  7. while(read(fd, &toInsert, sizeof(int)))
  8. {
  9. limit++;
  10. }
  11.  
  12.  
  13. while(ndx = --limit)
  14. {
  15. lseek(fd,limit*sizeof(int),SEEK_SET);
  16. read(fd,&toInsert, sizeof(int));
  17. while(ndx-- >= 0)
  18. {
  19. lseek(fd, -2, SEEK_CUR);
  20. read(fd, &temp, sizeof(int));
  21. if(temp > toInsert)
  22. {
  23. lseek(fd, ndx*sizeof(int), SEEK_SET);
  24. write(fd, &toInsert, sizeof(int));
  25. lseek(fd,limit*sizeof(int),SEEK_SET);
  26. write(fd, &temp, sizeof(int));
  27. toInsert = temp;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement