A yard is configured as follows:
ERROR spur capacity exceeded!If there is an attempt to place more than the maximum number of cars of a spur, discard the car that would cause the spur to overflow.
In a similar manner, if an attempt is made to remove a car from an empty spur the program should report the error message
ERROR spur is empty, cannot remove a car!If this error occurs, any function responsible for returning a car should return ERROR_CAR which is defined below.
LOCAL
C
B
A
LOCAL
F
E
D
C
B
A
LOCAL YARD
C
B
A
Remove A from the Local spur and place it on the Yard spur.
LOCAL YARD
C A
B
Remove B from the Local spur and place it on the Yard spur.
LOCAL YARD
C A
B
Remove C from the Local spur and place it on the Yard spur.
LOCAL YARD
A
B
C
Remove D from the arriving train and place it on the Yard spur.
LOCAL YARD
A
B
C
D
Remove E from the arriving train and place it on the Yard spur.
Remove F from the arriving train and place it on the Yard spur.
LOCAL YARD
A
B
C
D
E
F
Remove F from the Yard spur and place in the the Local spur.
LOCAL YARD
F A
B
C
D
E
Remove E from the Yard spur and place in the the Local spur.
Remove D from the Yard spur and place in the the Local spur.
Remove C from the Yard spur and place in the the Local spur.
LOCAL YARD
F A
E B
D
C
Remove B from the Yard spur and place in the the Local spur.
Remove A from the Yard spur and place in the the Local spur.
LOCAL YARD
F
E
D
C
B
A
Cars will never arrive on the yard spur.
Remove all cars from the local spur and place them in the source spur.
While the source spur is not empty
remove first car on the source spur
put the car on the local spur
if the destination of the first car in the local spur is not local
while the destination of the car in the front of the yard spur is larger than the destination of the car in the local spur
remove the car from the yard spur and place it on the source spur
remove the car from the local spur and put it on the yard spur
remove all cars from the yard spur and place them in the source spur.
For the following example, assume that for car A-n n is the destination. Assume that this is station 0. The local spur contains A-1 B-3 and the west spur contains C-2 D-0 E-4.
Initial Configuration
LOCAL YARD
B-3
WEST A-1
E-4 D-0 C-2
Remove A from the Local spur and place it on the West spur.
Remove B from the Local spur and place it on the West spur.
WEST LOCAL YARD
E-4 D-0 C-2 A-1 B-3
Remove B from the West spur and place it on the Local spur.
(since the yard spur is empty)
Remove B from the Local spur and place it on the Yard spur.
LOCAL YARD
WEST B-3
E-4 D-0 C-2 A-1
Remove A from the West spur and place it on the Local spur.
LOCAL YARD
WEST A-1 B-3
E-4 D-0 C-2
(since the destination of A is less than the destination of B)
Remove A from the Local spur and place it on the Yard spur.
LOCAL YARD
B-3
WEST A-1
E-4 D-0 C-2
Remove C from the West spur and place it on the Local spur.
LOCAL YARD
C-2 B-3
WEST A-1
E-4 D-0
(since the destination of C is greater than the destination of A)
Remove A from the Yard spur and place it on the West spur.
LOCAL YARD
WEST C-2 B-3
E-4 D-0 A-1
(since the destination of C is less than the destination of B)
Remove C from the Local spur and place it on the Yard spur.
LOCAL YARD
B-3
WEST C-2
E-4 D-0 A-1
(A will now be moved to the yard spur via the local spur)
LOCAL YARD
B-3
C-2
WEST A-1
E-4 D-0
(D will be placed on the local spur, it will never be removed)
LOCAL YARD
D-0 B-3
C-2
WEST A-1
E-4
(E will be placed on the local spur)
LOCAL YARD
D-0 B-3
E-4 C-2
WEST A-1
(All of the cars in the yard will be removed and placed on the west spur
since all have destinations less than E)
LOCAL YARD
D-0
WEST E-4
A-1 C-2 B-3
(The process will continue until)
LOCAL YARD
D-0 E-4
B-3
C-2
WEST A-1
(remove all cars from the yard and place them in the west spur)
LOCAL YARD
WEST D-0
A-1 C-2 B-3 E-4
Only the East and West spurs will be sorted.
For example if the east spur contains ABC and the west spur contains DEF the command move east west would produce the following
WEST EAST
FED ABC
Remove A from the East spur and place it on the West spur.
WEST EAST
FEDA BC
Remove B from the East spur and place it on the West spur.
Remove C from the East spur and place it on the West spur.
WEST EAST
FEDABC
The XXX spur contains: Name, Destination Name, DestinationEach car should be indented with a tab. The cars should be printed from front to back. A blank line should be printed after the last car. For example if the west spur contains A-0 B-1 C-2 :
WEST EAST
CBA
The command print west should produce
The West spur contains: A, 0 B, 1 C, 2
A trainlist consists of a comma separated list of train cars, listed from front to back. A train car consists of a car id, which is a unique string, a colon and a destination, which is a string. See below for a full list of destinations.
Assume all spurs are empty. The command arrive Local C:Oakland,B:Cleveland,A:Denver would produce the following
LOCAL YARD
C
B
WEST A EAST
Enter the file name =>There should be a space after the > in this prompt. Note, this prompt does not include the newline character. However, after you have read the file name, please print a newline character.
The first word in the file will be the station name. This will be a valid destination.
The program should then attempt to execute the commands in the file. You may assume all commands are valid.
The following is an example of a valid input file
Edinboro arrive local A:Albion,B:Cambridge Springs ArrIve wEsT C:Bradford,D:Edinboro,E:Erie SORT wesT Move west East Depart East
Executing commandwhere command is the command as it appears in the input.
A train departs from the Xxxx spur.
Sorting the Xxxx spur. <commands to accomplish the sort>
Moving from the Xxxx spur to the Xxxx spur. <commands to accomplish the move>
New train arriving on the Xxxx spur. <commands to accomplish the arrival>Note, this will include moving the current train to the yard. When adding a car to the spur print
Remove XXX from the arriving train and place it on the Yard spur.
Thank you for using the Xxxx Switching StationWhere Xxxx is the name of the station.
will accomplish creating this constant assuming that the name/id field is first and the destination field is second in your car structure.
-g -O3 -Wall -Wextra -Wuninitialized -pedantic -Wshadow -std=c++14