Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Jo has represented each stack of tyres as a stack ADT using the LinkedStack implementation ( see 7 . 1 . 3 ) . Each
Jo has represented each stack of tyres as a stack ADT using the LinkedStack implementation see Each element in the stack is an integer representing the tyre diameter in millimetres. The whole shop is represented as a dictionary of stacks, with the stack being the value and the key being one or more uppercase letters which Jo uses to identify the stack. The following code creates two stacks of tyres A and B and adds some sample tyres to them. tyreshop dict tyreshopSTACKA LinkedStack tyreshopSTACKApush tyreshopSTACKApush tyreshopSTACKB LinkedStack tyreshopSTACKBpush The results of this are illustrated below:image When a new tyre is received into stock, Jo needs to identify the most suitable of the existing stacks to put it on Jo does this by applying two rules: The diameter of the top tyre must be as close as possible to the new tyre without being smaller than the new tyre. The candidate stack must be as short as possible. Rule takes priority over rule Example: Stack C contains tyres, the top one being mm Stack D contains tyres, the top one being mm Stack E contains tyres, the top one being mm Note this example discounts stacks A and B from the prior example. If the new tyre was mm Jo would choose stack C since: The top tyre on the stack is the closest size to the new tyre without being smaller than it It is shorter than the other potential stack, E Stack D is discounted as although it is shorter than the other stacks, it does not meet the criteria of rule Note that if stack E were only tyres high, then Jo's method would give both stack C and stack E as options.
Jo has represented each stack of tyres as a stack ADT using the LinkedStack implementation see Each element in the stack is an integer representing the tyre diameter in millimetres. The whole shop is represented as a dictionary of stacks, with the stack being the value and the key being one or more uppercase letters which Jo uses to identify the stack.
The following code creates two stacks of tyres A and B and adds some sample tyres to them.
tyreshop dict
tyreshopSTACKA LinkedStack
tyreshopSTACKApush
tyreshopSTACKApush
tyreshopSTACKB LinkedStack
tyreshopSTACKBpush
The results of this are illustrated below:image
When a new tyre is received into stock, Jo needs to identify the most suitable of the existing stacks to put it on Jo does this by applying two rules:
The diameter of the top tyre must be as close as possible to the new tyre without being smaller than the new tyre.
The candidate stack must be as short as possible. Rule takes priority over rule
Example:
Stack C contains tyres, the top one being mm
Stack D contains tyres, the top one being mm
Stack E contains tyres, the top one being mm
Note this example discounts stacks A and B from the prior example.
If the new tyre was mm Jo would choose stack C since:
The top tyre on the stack is the closest size to the new tyre without being smaller than it
It is shorter than the other potential stack, E
Stack D is discounted as although it is shorter than the other stacks, it does not meet the criteria of rule
Note that if stack E were only tyres high, then Jo's method would give both stack C and stack E as options.
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