Professional Documents
Culture Documents
File Allocation
Sequence and Indexed File Allocation
Aim:
To simulate the Sequence and Indexed file Allocation Algorithm.
Algorithm:
while switch:
name = input("Enter the File Name : ")
for i in range(len(objects)):
# Checking whether the entered file name already exists
if name == objects[i].name:
print("File name already exists, please enter another name")
switch_1 = False
break
switch_1 = True
if switch_1:
switch = False
while switch_2:
starting_allocated_location = int(input("Enter the Starting Memory Location : "))
for i in range(len(objects)):
# Checking whether the entered file name already exists
if objects[i].starting_memory_block <= starting_allocated_location <=
objects[i].ending_memory_block:
print("The entered memory location is already allocated, please enter another
memory location")
switch_3 = False
break
switch_3 = True
if switch_3:
switch_2 = False
try:
size = int(input("Enter the size : "))
except ValueError:
print("Enter a Valid Size")
size = int(input("Enter the size : "))
objects.append(File(
name,
size,
starting_allocated_location
))
variable += 1
# Main Function
def main():
variable = 0
while True:
print("""\nSequential File Allocation
1. Creation
2. Delete
3. Display
4. Exit
""")
try:
option = int(input("Enter the Option : "))
except ValueError:
print("Enter a Valid Option")
option = int(input("Enter the Option : "))
if option == 1:
create(variable)
elif option == 2:
delete(variable)
elif option == 3:
display()
elif option == 4:
exit()
else:
print("Wrong Option")
if __name__ == "__main__":
main()
Output (Sequential File Allocation):
Program (Indexed File Allocation):
for i in range(10):
self.allocated.append(self.size / 10)
if switch_1:
switch = False
try:
size = int(input("Enter the size : "))
except ValueError:
print("Enter a Valid Size")
size = int(input("Enter the size : "))
objects.append(File(
name,
size
))
variable += 1
# Main Function
def main():
variable = 0
while True:
print("""\nIndexed File Allocation
1. Creation
2. Delete
3. Display
4. Exit
""")
try:
option = int(input("Enter the Option : "))
except ValueError:
print("Enter a Valid Option")
option = int(input("Enter the Option : "))
if option == 1:
create(variable)
elif option == 2:
delete(variable)
elif option == 3:
display()
elif option == 4:
exit()
else:
print("Wrong Option")
if __name__ == "__main__":
main()