Objective
In the Command pattern each action is an object with a method to execute it and another to undo it. By storing the executed commands in a stack, undoing is popping the last one and reverting it.
Instructions
- The text starts empty. The first line has the number
nof commands:append word(adds at the end),delete k(deletes the lastkcharacters),undo(reverts the last append or delete command, if any) andshow(shows the text).
5
append hola
append mundo
delete 5
show
undo
hola
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise