From 28df18ed80143fad4f3deebebf8f821787edc875 Mon Sep 17 00:00:00 2001 From: TanmayMachkar Date: Sat, 12 Oct 2024 17:44:02 +0530 Subject: [PATCH] b6 code added --- ... best fit, first fit, next fit and worst.cpp | 115 ++++++++++++++++++ README.md | 2 +- 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 Codes/Group B/Assignment - 6/Memory placement strategies – best fit, first fit, next fit and worst.cpp diff --git a/Codes/Group B/Assignment - 6/Memory placement strategies – best fit, first fit, next fit and worst.cpp b/Codes/Group B/Assignment - 6/Memory placement strategies – best fit, first fit, next fit and worst.cpp new file mode 100644 index 0000000..081367a --- /dev/null +++ b/Codes/Group B/Assignment - 6/Memory placement strategies – best fit, first fit, next fit and worst.cpp @@ -0,0 +1,115 @@ +#include +using namespace std; + +int blksize[] = {100, 500, 200, 300, 600}; +int processes[] = {212, 417, 112, 426}; + +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 && (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) + { + blk[j] = blk[j] - pr[i]; + cout<<"\nProcess with value "<