From f598faff498f7b9ffea0aea36e9c09aadb75ea87 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Tue, 5 Nov 2024 00:21:16 +0530 Subject: [PATCH] Simplified and improved code B6. - Changed variable names and made prSize and blkSize global variables - Added note in main function --- Codes/Group B/Code-B6.cpp | 187 +++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 104 deletions(-) diff --git a/Codes/Group B/Code-B6.cpp b/Codes/Group B/Code-B6.cpp index a047ffb..7e1e2db 100644 --- a/Codes/Group B/Code-B6.cpp +++ b/Codes/Group B/Code-B6.cpp @@ -1,117 +1,96 @@ -#include +#include using namespace std; -int blksize[] = {100, 500, 200, 300, 600}; +int blocks[] = {100, 500, 200, 300, 600}; int processes[] = {212, 417, 112, 426}; +int blkSize = sizeof(blocks) / sizeof(blocks[0]); +int prSize = sizeof(processes) / sizeof(processes[0]); -void firstfit(int pr[], int pr_size, int blk[], int blk_size) -{ - for(int i = 0; i < pr_size; i++) - { - bool check = false; - for(int j = 0; j < blk_size; j++) - { - if((blk[j] - pr[i]) >= 0) - { - blk[j] = blk[j] - pr[i]; - cout<<"\nProcess with value "<= 0)) { + blocks[j] -= processes[i]; + check = true; + cout<= 0 && (blk[j] - pr[i]) < store) - { - k = j + 1; - store = blk[j] - pr[i]; - check = true; - } - } - if(!check) - { - cout<<"\nProcess with value "<= 0 && (blk[j] - pr[i]) > store) - { - k = j + 1; - store = blk[j] - pr[i]; - check = true; - } - } - if(!check) - { - cout<<"\nProcess with value "<= 0) { + blocks[j] = blocks[j] - processes[i]; + cout<= 0) - { - blk[j] = blk[j] - pr[i]; - cout<<"\nProcess with value "<= 0 && (blocks[j] - processes[i]) < store) { + k = j + 1; + store = blocks[j] - processes[i]; + check = true; + } + } + if (check == false) { + cout<= 0 && (blocks[j] - processes[i] > store))) { + k = j + 1; + store = blocks[j] - processes[i]; + check = true; + } + } + if (check == false) { + cout<