2
1

b6 code added

This commit is contained in:
Tanmay 2024-10-12 17:44:02 +05:30
parent 1a105a3be4
commit 28df18ed80
2 changed files with 116 additions and 1 deletions

View File

@ -0,0 +1,115 @@
#include<iostream>
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 "<<pr[i]<<" allocated at block "<<j+1;
check = true;
break;
}
}
if(!check)
{
cout<<"\nProcess with value "<<pr[i]<<" not allocated";
}
}
}
void bestfit(int pr[], int pr_size, int blk[], int blk_size)
{
for(int i = 0; i < pr_size; i++)
{
bool check = false;
int k, store = 999;
for(int j = 0; j < blk_size; j++)
{
if((blk[j] - pr[i]) >= 0 && (blk[j] - pr[i]) < store)
{
k = j + 1;
store = blk[j] - pr[i];
check = true;
}
}
if(!check)
{
cout<<"\nProcess with value "<<pr[i]<<" not allocated";
}
else{
blk[k - 1] = blk[k - 1] - pr[i];
cout<<"\nProcess with value "<<pr[i]<<" allocated at block "<<k;
}
}
}
void worstfit(int pr[], int pr_size, int blk[], int blk_size)
{
for(int i = 0; i < pr_size; i++)
{
bool check = false;
int k, store = -1;
for(int j = 0; j < blk_size; j++)
{
if((blk[j] - pr[i]) >= 0 && (blk[j] - pr[i]) > store)
{
k = j + 1;
store = blk[j] - pr[i];
check = true;
}
}
if(!check)
{
cout<<"\nProcess with value "<<pr[i]<<" not allocated";
}
else{
blk[k - 1] = blk[k - 1] - pr[i];
cout<<"\nProcess with value "<<pr[i]<<" allocated at block "<<k;
}
}
}
void nextfit(int pr[], int pr_size, int blk[], int blk_size)
{
int j = 0;
for(int i = 0; i < pr_size; i++)
{
bool check = false;
for(int k = 0; k < blk_size; k++)
{
if((blk[j] - pr[i]) >= 0)
{
blk[j] = blk[j] - pr[i];
cout<<"\nProcess with value "<<pr[i]<<" allocated at block "<<j+1;
check = true;
break;
}
j = (j + 1) % blk_size;
}
if(!check)
{
cout<<"\nProcess with value "<<pr[i]<<" not allocated";
}
}
}
int main()
{
int blk_size = sizeof(blksize)/sizeof(blksize[0]);
int pr_size = sizeof(processes)/sizeof(processes[0]);
//firstfit(processes, pr_size, blksize, blk_size);
//bestfit(processes, pr_size, blksize, blk_size);
//worstfit(processes, pr_size, blksize, blk_size);
nextfit(processes, pr_size, blksize, blk_size);
return 0;
}

View File

@ -13,7 +13,7 @@ This repository serves as a comprehensive resource for the Systems Programming a
- [SJF (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/SJF%20%28Preemptive%29.cpp)
- [Priorty (Non-Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/Priority%20%28Non-Preemptive%29.cpp)
- [Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/Round%20Robin%20%28Preemptive%29..cpp)
6. [Memory Placement Strategies Best Fit, First Fit, Next Fit and Worst Fit]
### Notes