Circular Array, if array is converted into string Python code for: - def parse_c
ID: 3592927 • Letter: C
Question
Circular Array, if array is converted into string
Python code for:
- def parse_command(self, command)
where;
def main():
fp = open(input("Insert Filename (with extension) for input: ").strip())
output = open(input("Insert Filename (with extension) for output: ").strip(), 'w')
q = CircularQueue()
for command in fp.readlines():
q.parse_command(command.strip(' '))
print(q, file=output)
fp.close()
main()
inputfile:
a 22
r
a 93
a 41
a 13
a 2
a 17
a 85
r
a 78
Program will process two types of commands. The first is of the form “a X”, where “a” denotes adding to the back of queue and X is the number you want to add. The second is of the form “r”, which stands for removing an element from the front of the queue.
Explanation / Answer
def main():
fp = open(input("Insert Filename (with extension) for input: ").strip())
output = open(input("Insert Filename (with extension) for output: ").strip(), 'w')
q = CircularQueue()
for command in fp.readlines():
q.parse_command(command.strip(' '))
print(q, file=output)
fp.close()
main()