$27
Bus Route Editor
Supporting the Reverse Operation
NTHU ITRI
Mackay
HCHS TSMC
KFSH
EECS Data Structures, HW3,
Bus Route Editing 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 srcdst
• 2: In addition to srcdst, also insert the same stop in between
dstsrc if appropriate
• DELETE (name)
• Delete the named bus stop
• REVERSE ()
• Reverse the entire route
NTHU
NTHU Mackay TSMC
TSMC
Insert (NTHU, TSMC, Mackay, 2)
Insert (TSMC, NTHU, Mackay, 2)
or
src, dst, new, method
NTHU TSMC
NTHU
Mackay
TSMC
Insert (NTHU, TSMC, Mackay, 1)
src, dst, new, method
NTHU TSMC
NTHU TSMC
Mackay
Insert (TSMC, NTHU, Mackay, 1)
src, dst, new, method
NTHU TSMC
Mackay
NTHU TSMC
Mackay KFSH
Insert (TSMC, Mackay, KFSH, 1)
Insert (TSMC, Mackay, KFSH, 2)
or
src, dst, new, method
Delete (Mackay)
NTHU ITRI
Mackay
HCHS MTK
KFSH
NTHU ITRI
Mackay
HCHS MTK
KFSH
NTHU ITRI
Mackay
HCHS MTK
KFSH
Delete (ITRI)
NTHU
Mackay
HCHS MTK
KFSH
Delete (HCHS)
NTHU
Mackay
ITRI MTK
KFSH
NTHU ITRI
Mackay
HCHS MTK
KFSH
Delete (MTK)
NTHU
Mackay
ITRI HCHS
KFSH
NTHU ITRI
Mackay
HCHS MTK
KFSH
Delete (TSMC)
NTHU ITRI
Mackay
HCHS
TSMC
KFSH MTK
NTHU ITRI
Mackay
HCHS
KFSH MTK
NTHU Mackay TSMC
NTHU Mackay TSMC
Reverse ()
NTHU ITRI
Mackay
HCHS
KFSH MTK
NTHU ITRI
Mackay
HCHS
KFSH MTK
Reverse ()
Other Notes
• The bus route contains NTHU and TSMC in the
beginning
• NTHU is never deleted
Input
16
REVERSE
INSERT NTHU TSMC APPLE 2
REVERSE
INSERT NTHU APPLE HTC 2
INSERT HTC APPLE ASUS 2
INSERT NTHU HTC WE 1
INSERT NTHU WE HI 2
INSERT ASUS HTC ARE 1
INSERT ARE HTC AWESOME 1
DELETE TSMC
INSERT HTC NTHU COOL 2
REVERSE
DELETE APPLE
DELETE HTC
DELETE ASUS
REVERSE
Number of operations bellow Each line is an operation
Output
• Traverse the final bus route from NTHU and back to
NTHU
NTHU->HI->WE->ARE->AWESOME->COOL->NTHU
NTHU ARE
COOL
HI
AWESOME
WE