Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA: Stacks and Queues: Railroad cars are to -- enter from the right and are sent to the output on the left by routing
IN JAVA: Stacks and Queues: Railroad cars are to -- enter from the right and are sent to the output on the left by routing -- through the stack. Each car can be brought into the stack and removed at -- any time. This program aids the switch yard manager in determining the -- ordering of the outgoing cars. The program expects two sequences of cars. -- The first is the incomming sequence, and the second is the desired out-going -- sequence. The program tells the manager if the mapping can be performed -- and the ordering of the pushes and pops. -- For example: -- an input of: 1 2 3 4 can be mapped to an output of 4 3 2 1 using the sequence -- -- push push push push pop pop pop pop -- -- but -- -- an input of: 1 2 3 4 cannot be mapped to an output of 4 2 3 1 -- -- Specifications: -- -- 1. This program will read pairs of input sequences consisting of up to -- 10 strings -- -- 2. The program prints the sequence of push and pop operations that are -- needed to be performed. -- -- 3. If the mapping can be accomplished successfully, outputs: -- -- The input can be mapped to the output -- -- 4. If the mapping cannot be accomplished successfully, outputs: -- -- The input cannot be mapped to the output -- -- The preceeding examples would produce the output: -- -- Attempting to map the input 1 2 3 4 to the output 4 3 2 1 -- The sequence of moves are: push push push push pop pop pop pop -- The input can be mapped to the output -- -- Attempting to map the input 1 2 3 4 to the output 4 2 3 1 -- The sequence of moves are: push push push push pop -- The input cannot be mapped to the output -- -- 5. The program processes all input to the end of the input. -- -- -- Error Handling: -- -- 1. If the user attempts to enter more than the maximum allowable number of -- elements the program outputs: -- -- A maximum of only 10 items are allowed to be input for each sequence - Please re-enter -- -- The input lines are cleared for the next input pair.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started