-
Notifications
You must be signed in to change notification settings - Fork 52
/
Best_fit.py
31 lines (27 loc) · 957 Bytes
/
Best_fit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def bestFit(blockSize, m, processSize, n):
allocation = [-1] * n
for i in range(n):
bestIdx = -1
for j in range(m):
if blockSize[j] >= processSize[i]:
if bestIdx == -1:
bestIdx = j
elif blockSize[bestIdx] > blockSize[j]:
bestIdx = j
if bestIdx != -1:
allocation[i] = bestIdx
blockSize[bestIdx] -= processSize[i]
print("Process No. Process Size Block no.")
for i in range(n):
print(i + 1, " ", processSize[i],
end=" ")
if allocation[i] != -1:
print(allocation[i] + 1)
else:
print("Not Allocated")
if __name__ == '__main__':
blockSize = [100, 500, 200, 300, 600]
processSize = [212, 417, 112, 426]
m = len(blockSize)
n = len(processSize)
bestFit(blockSize, m, processSize, n)