12213 - Bus Route Linked List   

Description

A bus route editor needs to support two operations:

INSERT (src, dst, new, method)

  • src: the name of the source bus stop
  • dst: the name of the destination bus stop, which is next to the src stop
  • new: the name of the newly added bus stop
  • method:
    • 1: insert the new stop in between src-->dst
    • 2: In addition to src-->dst, also insert the same stop in between dst-->src if appropriate

DELETE (name)

  • Delete the named bus stop

HINT: Use Linked Lists.

Input

The first number is the number of the following operations.  Each of the following line contains an operation.

Two additional rules:

  • The bus route contains NTHU and TSMC in the beginning.
  • NTHU is never deleted

Output

Traverse the final bus route from NTHU and back to NTHU.

Sample Input  Download

Sample Output  Download

Tags

Homework



Discuss