Menu

Starter code:   public class TrainSorter {  public void sort(TrainYard yard) {    // Note that you can System.out.println(yard) for debugging.    // insert your code here.  } }     Sta. This …

Question

Starter code: public class TrainSorter { public void sort(TrainYard…

Image transcription text

This would yield the following output INPUT: [Car #1, Car #2, Car #3, Car #4, Car #5] OUTPUT: SIDING:
INPUT: OUTPUT: [Car #5, Car #4, Car #3, Car #2, Car #1] SIDING: Moves so far: 1. Move Car #5 ” Input to
Output . Move Car #4 ” Input to Output . Move Car #3 ” Input to Output . Move Car #2 ” Input Show more
Show more

Image transcription text

Train sorting using stacks For this assignment you are to write a program that sorts the cars on a train.
Consider the following diagram of a train track. IIIIIIIIIEKiIIIIIIIII Cars come in from the left and exit on
the right hand side. They can also move onto the “siding” track to the bottom. At theShow more
Show more

Starter code:

 

public class TrainSorter {
 public void sort(TrainYard yard) {
   // Note that you can System.out.println(yard) for debugging.
   // insert your code here.
 }
}
 

 

Sta

OR

Leave a Reply

Your email address will not be published. Required fields are marked *