Suppose you're given a scenario where you're tasked to code an album editor with the use of LinkedList. Given that you have 2 albums A and B where photos can be inserted, deleted, previewed and undo, how do I go about implementing the undo method?
The input would be: The first line of input will contain a single integer N, the number of operations. It is guaranteed that 0 < N ≤ 500. N lines of input will follow. Each line of input will correspond to one operation.
Among these, it is guaranteed that all albumID parameters will be either “A” or “B”. Also, all position parameters will be an integer between 0 and 1,000,000,000 (1 billion) as well. In addition, all photoID parameters will be an integer between 0 and 1,000,000,000 (1 billion).
e.g. an example of Insert would be:
public void INSERT(Scanner sc) {
int a = sc.nextInt();
int b = sc.nextInt();
if (x.split("\\s+")[1].equals("A"){
albumA.add(a,b);
Hence, how do I implement UNDO(albumID) with this description:
Description This operation will be provided with a single parameter: albumID and you are supposed to undo the last change to the album identified by albumID. A change to the album is defined as either an insert operation or a delete operation. An undo operation is not considered as a change to the album. In addition, if an insert or delete operation was ignored, it is also not considered as a change to the album.
- In the case of an insert operation, the corresponding undo action is to remove the inserted photo.
- In the case of a delete operation, the corresponding undo action is to restore (insert back) the deleted photo (in the same position).