Assessment - 6: Question 1: Write The C Program To Implement A Linked List File Allocation Method
Assessment - 6: Question 1: Write The C Program To Implement A Linked List File Allocation Method
Name: M Vinayak
Regno: 20BDS0303
3. Initialize the helper function to return new linked list node from the heap
13. End
Source Code
Node(){
Output
Algorithm
1. Start
8. End
Source Code
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int files[50], indexBlock[50], indBlock, n;
void recurse1();
void recurse2();
void recurse1() {
printf("Enter the index block: ");
scanf("%d", &indBlock);
if (files[indBlock] != 1) {
printf("Enter the number of blocks and the number of files needed for the index %d on the disk: ", indBlock);
scanf("%d", &n);
}
else {
printf("%d is already allocated\n", indBlock);
recurse1();
}
recurse2();
}
void recurse2() {
int ch;
int flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &indexBlock[i]);
if (files[indexBlock[i]] == 0)
flag++;
}
if (flag == n) {
for (int j = 0; j < n; j++) {
files[indexBlock[j]] = 1;
}
printf("Allocated\n");
printf("File Indexed\n");
for (int k = 0; k < n; k++) {
printf("%d -> %d : %d\n", indBlock, indexBlock[k],
files[indexBlock[k]]);
}
}
else {
printf("File in the index is already allocated\n");
printf("Enter another indexed file\n");
recurse2();
}
printf("Do you want to enter more files?\n");
printf("Enter 1 for Yes, Enter 0 for No: ");
scanf("%d", &ch);
if (ch == 1)
recurse1();
else
exit(0);
return;
}
int main()
{
for (int i = 0;i < 50;i++)
files[i] = 0;
recurse1();
return 0;
}
Output
Question 3: Write the C program to implement contiguous file
allocation method.
Algorithm
1. Start the program.
11. End
Source Code
recurse(files);
exit(0);
for(i=0;i<50;i++)
recurse(files);
Output