Question: Q 1 ( a ) Jo has represented each stack of tyres as a stack ADT using the Linked Stack implementation ( see 7 .
Qa
Jo has represented each stack of tyres as a stack ADT using the Linked Stack
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 STACKA and STACKB and adds some sample tyres to them.
tyreshop diet
tyreshopSTACKA LinkedStack
tyreshopSTACKApush
tyreshopSTACKApush
tyreshopSTACKB LinkedStack
tyreshopSTACKBpush
The results of this are illustrated below:
Stack A: Stack B:
mm tyre
mm tyre mm tyre
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.
Qai Outline an algorithm in English which will return a list of the stack keys which are suitable candidates for the new tyre to be placed on according to Jo's rules above.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
