In this homework, you are asked to use linked list to simulate typing a string. You need to implement four operations, i.e., type, move, backspace and print.
Notice: <string> is allowed, but other STL are not allowed
There are four operations to be implemented.
1. Type abcd:
a string, e.g., abcd, follows the operation Type. You need to add each character as a new node after the cursor (游標). Each time a new node is added, the cursor moves to the end of the new added node.
For example, assume we have a linked list “abc|” and “|” is the cursor. After the operation Type defg, the linked list becomes “abcdefg|”.
(Note that the string consists only [0-9,A-Z,a-z], and you don’t have to output the cursor)
2. Move N:
N is an integer. If N>0, the cursor moves rightward N characters. If N<=0, the cursor moves leftward N characters. If the cursor moves to the very front/end of the linked list, then stop.
For example, assume we have a linked list “abc|” and “|” is the cursor. After the operation “Move -4”, the linked list becomes “|abc”.
( Note that -1000000<N<1000000. )
3. Backspace:
Delete the character in front of the cursor. If there is no character in front of the cursor, then do nothing.
For example, assume we have this linked list “abc|” and “|” is the cursor. After the operation “Backspace”, the linked list becomes “ab|”.
4. Print: Output all the characters stored in the linked list and shift to new line.
There are M operations specified in the input lines and 0<M<300000.
Each Movement operation follows an integer N indicating the moving distance, where -1000000<N<1000000.
For every operation “Print”, you need to output all characters stored in the linked list and shift a newline.