11406 - DS QUIZ2(2)   

Description

Please implement the 3 basic operations on a linked list, i.e., move, type, and delete.

You need to implement a linked list for this quiz, otherwise no point will be given.

#include <vector> is not allowed.

Input

There are several link list operations specified in the input lines. When the input ends, the program should output the result.

 

Please note that there is a (virtual) cursor. The cursor works as follows.

  1. If the list is empty, the cursor points to NULL
  2. After a character (node) is inserted, the cursor is pointing to the inserted character (node).
  3. After a character (node) is deleted, the cursor should be pointing to the node preceding the delete node. If the deleted node is the first node, then the cursor points to the first node of the list after the deletion.

 

The three operations are as follows.

1."t abcde": Insert 5 nodes containing ‘a’, ‘b’, ‘c’, ‘d’, and ‘e’ after the cursor.

        “abcde” is any series of characters that would be specified in the input operation. Note that after the insertion, the cursor should           point to e.
        The characters only include alphanumeric characters, i.e., [A-Za-z0-9].

        Please note that the number of characters inserted in each operation will not exceed 20,000.

 

2."m i": Move the cursor of link list i steps.

        If i >= 0, the cursor should move i nodes rightward.

        If i < 0, the cursor should move i nodes leftward.

        Note:如果在移動的過程中,current pointer已經到達盡頭,就停止動作。
        Note: If after the operation, the cursor is moved beyond the last (first) node, the cursor should stop at the last (first) node.

        Also note |i|<=2147483647

 

        For example the input:

        t hello

        m -100

        t ha

        m 100

        t xyz <-- The content in the linked list after this operation is: hahelloxyz

 

3."delete": Delete the node pointed by the cursor.

        For example the input:

        t abc

        d <--Now the current pointer should be ‘b’. The content in the linked list after this operation is: ab

Output

The output is the linked list char elements.
NO endl after the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss