Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int mloc;
- struct node *next;
- };
- struct node *newnode = NULL, *ptr = NULL;
- void main()
- {
- int n, i, j, k, fb[50], mb[100];
- struct node* ll[50];
- printf("Enter the number of files: ");
- scanf("%d", &n);
- printf("Enter the number of blocks for each file: \n");
- for(i = 0; i < n; i++)
- {
- printf("File %d: ", i+1);
- scanf("%d", &fb[i]);
- ll[i] = NULL;
- }
- for(i = 0; i < 100; i++)
- mb[i] = rand()%2;
- //printf("The memory block: \n");
- printf("\nDISK:\n\n\t0\t1\t2\t3\t4\t5\t6\t7\t8\t9\n");
- for (i = 0; i<100; i++){
- if (i % 10 == 0)
- printf("\n%d\t", i);
- printf("%d\t", mb[i]);
- }
- printf("\n");
- for(i = 0; i < n; i++)
- {
- k = 0;
- for(j = 0; j < 100; j++)
- {
- if(mb[j] == 0)
- {
- newnode = (struct node*)malloc(sizeof(struct node));
- newnode -> mloc = j;
- newnode -> next = NULL;;
- if(ll[i] == NULL)
- ll[i] = newnode;
- else
- {
- ptr = ll[i];
- while(ptr -> next != NULL)
- ptr = ptr -> next;
- ptr -> next = newnode;
- }
- mb[j] = 1;
- k++;
- if(k == fb[i])
- break;
- }
- }
- }
- printf("\n\nLinked lists are: ");
- for(i = 0; i < n; i++)
- {
- printf("\nFile %d: ", i+1);
- ptr = ll[i];
- while(ptr != NULL)
- {
- printf("%d ", ptr -> mloc);
- ptr = ptr -> next;
- }
- }
- printf("\n");
- }
- OUTPUT
- Enter the number of files: 4
- Enter the number of blocks for each file:
- File 1: 3
- File 2: 2
- File 3: 4
- File 4: 12
- DISK:
- 0 1 2 3 4 5 6 7 8 9
- 0 1 0 1 1 1 1 0 0 1 1
- 10 0 1 0 1 1 0 0 0 0 0
- 20 1 0 1 1 0 0 0 1 1 1
- 30 1 0 0 0 1 1 1 0 1 0
- 40 1 1 1 1 0 1 0 0 1 0
- 50 1 0 1 0 0 1 0 0 0 1
- 60 1 1 0 1 0 1 0 1 1 1
- 70 0 1 0 1 0 1 0 0 1 0
- 80 1 0 0 0 0 0 1 1 0 1
- 90 0 0 0 0 1 0 0 0 0 1
- Linked lists are:
- File 1: 1 6 7
- File 2: 10 12
- File 3: 15 16 17 18
- File 4: 19 21 24 25 26 31 32 33 37 39 44 46
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement