Question: 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 7.1.3). 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.
tyre_shop = dict()
tyre_shop['STACK_A']= LinkedStack()
tyre_shop['STACK_A'].push(330)
tyre_shop['STACK_A'].push(310)
tyre_shop['STACK_B']= LinkedStack()
tyre_shop['STACK_B'].push(410)
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 1 takes priority over rule 2.
Example:
Stack C contains 3 tyres, the top one being 200mm.
Stack D contains 2 tyres, the top one being 300mm.
Stack E contains 4 tyres, the top one being 200mm.
Note this example discounts stacks A and B from the prior example.
If the new tyre was 190mm, 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 1.
Note that if stack E were only 3 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!