Advertisement
desdemona

merge duże bufory.

Nov 3rd, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. Phase I. (Creating runs)
  2. 1. Read first nb records of the file into the buffers and sort them using an
  3. efficient in-memory algorithm (QuickSort, HeapSort, …), creating a run of
  4. length nb.
  5. 2. Write the run to a disk file.
  6. 3. Repeat steps 1 and 2 until you reach the end of file.
  7.  
  8. Phase II. (Merging)
  9. 4. Merge first n-1 runs into longer runs (using one buffer for merging and
  10. writing) and write them to the disk.
  11. 5. Repeat step 4 for the next runs of the file.
  12. 6. Repeat steps 4 and 5 until one run is obtained.
  13.  
  14. Jak mam użyć jednego bufora do czytania/pisania?
  15. Czy tutaj całość odbywa się na dwóch plikach?
  16. Załóżmy, że robię tak:
  17.  
  18. faza 1
  19. while(plik1 niepusty)
  20. {
  21. Biorę sobię dużo rekordów z pliku 1, sortuję, zapisuje do pliku 2.
  22. }
  23.  
  24. no i wtedy mam w pliku 2 (ilość rekordów/dużo) serii.
  25.  
  26. faza 2
  27. while(plik2 niepusty)
  28. {
  29. znam dlugosc serii, więc merge dwoch serii z pliku2 ze sobą
  30. to do pliku1
  31. wtedy ilosc serii = ilość rekordów/(dużo*2)
  32. }
  33. i powtarzam faze 2, tyle ze z wieksza dlugoscia serii?
  34.  
  35. ale że jak?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement