d********w 发帖数: 363 | 1 http://geeksforgeeks.org/forum/topic/google-interview-question-
software-engineerdeveloper-about-algorithms-15
There is a file system on the disc. the disc has many sectors. Always
the first sector has the information about all the files.
A file data is divided into sectors. Each sector can have data from a
single file.
Each sector has 2 parts, data and the pointer to the next sector of the
file. Every last sector in the file has next pointer as null.
say a disk has 18 sectors numbered 1 to 18.
then the first sector would have this information about the file.
file1 = sec1 -> sec7->sec9 -> sec11 -> null
file2 = sec10 -> sec12-> null
etc.
Now the first sector has some error. Write an algo to reconstruct the
file information in the first sector. Write code in C.
我没懂题目意思,first sector出错如何重建? | n********y 发帖数: 66 | 2 file1 = sec1 -> sec7->sec9 -> sec11 -> null
file2 = sec10 -> sec12-> null
file1 should start from sec2 ?
For example
Sec1.block1: 2
block2: 10
block3: null
These data are lost. So we scan from Sec2, then follow pointer to 2,7,9,11
and record these positions. Write all the information as file1 to Sec1. Then
from next sector in 2-17 not used, do same thing.
when you're done, you get a your Sec1 back. |
|