Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 1 ( a ) Jo has represented each stack of tyres as a stack ADT using the Linked Stack implementation ( see 7 .

Q1(a)
Jo has represented each stack of tyres as a stack ADT using the Linked Stack
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 (STACK_A and STACK_B) and adds some sample tyres to them.
tyre_shop = diet()
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:
Stack A: Stack B:
310mm tyre
330mm tyre 410mm 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:
1. The diameter of the top tyre must be as close as possible to the new tyre without being smaller than the new tyre.
2. 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.
Q1(a)(i) 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Is the tone of the writing appropriate for the audience?

Answered: 1 week ago