Code Documentation for Task 1 and Task 2 pdf
Code Documentation for Task 1 and Task 2 pdf
The StringProcessor class in Python processes string operations in a sequential order using a
queue implemented with collections.deque. This approach ensures that operations are
handled in a First-In-First-Out (FIFO) manner, which aligns with the natural order of the input.
The queue is initialized with a list of operations, where the first element is the starting string,
followed by alternating operators (+ or -) and operands. Concatenation (+) appends the operand
string to the result, while subtraction (-) removes all occurrences of characters in the operand
from the result using Python’s string replacement method. The program demonstrates its
functionality with several test cases, showcasing di erent combinations of operations, such as
adding substrings, removing specific characters, and modifying complex strings. This design
e ectively handles a variety of scenarios while maintaining clarity and e iciency.