Posts

Search

Linked File Allocation

QUESTION DESCRIPTION

Write a program to simulate Linked File Allocation.With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhere on the disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointer to the next block.

TEST CASE 1

INPUT
5
A 10
64 22 12 45 13 65 33 99 44 21
B 4
78 32 44 11
C 8
5 9 3 8 53 17 33 77
D 5
74 22 11 66 44
E 6
88 33 22 55 44 11
A
OUTPUT
Filename No.of blocks
A 10 
Blocks Occupied
64 22 12 45 13 65 33 99 44 21

TEST CASE 2

INPUT
4
AN 7
84 22 46 14 95 123 65
HJ 8
34 63 77 22 11 56 98 12
JK 5
83 22 19 74 23
FG 3
89 223 667
MK
OUTPUT
File Not Found

Code : 

#include<iostream>
#include<string.h>
using namespace std;
struct file{
 string c;
   int arr[100],len; 
};
int main()
{
 int size;
   cin>>size;
   file myfile[size];
   for(int i=0;i<size;i++)
    {
     cin>>myfile[i].c;
       cin>>myfile[i].len;
       for(int j=0;j<myfile[i].len;j++)
          cin>>myfile[i].arr[j];
    }
   string find;
   cin>>find;
   int flag=0;
   for(int i=0;i<size;i++)
    {
       if(find.compare(myfile[i].c)==0)
        {
         cout<<"Filename No.of blocks\n";
           cout<<myfile[i].c<<" "<<myfile[i].len<<" \n";
           cout<<"Blocks Occupied\n";
           for(int j=0;j<myfile[i].len-1;j++)
              cout<<myfile[i].arr[j]<<" ";
           cout<<myfile[i].arr[myfile[i].len-1];
           flag=1;
            break;
        }
    }
 if(flag==0)
      cout<<"File Not Found";
}