Stacks: Railroad switching network, A program is to be written to model a railro
ID: 3548903 • Letter: S
Question
Stacks: Railroad switching network,
A program is to be written to model a railroad switching yard. One part of the switching network consists of a main track and a siding that contains four exits onto which cars may be shunted and removed later. Railroad cars are numbered 1-7 on the right track(randomly arranged or entered by the user), they have to be moved to the left track (they have to be sorted in the left track), using the four exits. A car may be moved directly to the left track, or to one of the exits then to the left track. Use stacks to solve the problem.
on Java Programming
The order of the cars on the right track (random or by user)
Output
You should show a script showing the car number and the source and destination till the final solution is reached.
Explanation / Answer
}while(flag!=0);
start.push(number);
count++;
}
/*if(start.full())
for(int i=0;i<7;i++)
cout<<start.pop(i);
cout<<"Press any key to continue"*/
}
//############################################################################################
int GetNonNegInt(void)//validation if the user entered a charcter, Decimal or negative number
{
const int maxsize=100;
int stringsize, // size of input string
i=0, // index
num; // return value
char input[maxsize]; //inout string
bool valid; //boolian value for valid string
cin>>input;
stringsize=strlen(input);
valid=true;
if(stringsize==0) //Test for empty string
valid=false;
//check for all digits in input
while(valid && iINT_MAX) //overflow
num = -1;
else num = atoi(input); //valid input
else num = -1; //non digits in input
return num;
}[/code]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.