26 lines
908 B
Python
26 lines
908 B
Python
def next_fit(memory_blocks, process_sizes):
|
|
allocation = [-1] * len(process_sizes)
|
|
next_index = 0
|
|
|
|
for i in range(len(process_sizes)):
|
|
while next_index < len(memory_blocks):
|
|
if memory_blocks[next_index] >= process_sizes[i]:
|
|
allocation[i] = next_index
|
|
memory_blocks[next_index] -= process_sizes[i]
|
|
next_index = (next_index + 1) % len(memory_blocks) # Move to next block
|
|
break
|
|
next_index += 1
|
|
|
|
print("\nNext Fit Allocation:")
|
|
for i in range(len(process_sizes)):
|
|
if allocation[i] != -1:
|
|
print(f"Process {i+1} allocated to Block {allocation[i]+1}")
|
|
else:
|
|
print(f"Process {i+1} not allocated")
|
|
|
|
# Example Memory Blocks and Process Sizes
|
|
memory_blocks = [100, 500, 200, 300, 600]
|
|
process_sizes = [212, 417, 112, 426]
|
|
|
|
next_fit(memory_blocks, process_sizes)
|