Scholar EoT Test Queues 3.1&3.2

  • Sean Stratton
    Participant

    First year of AH, so be gentle with me it’s been a while since I had to think about these.

    Question

    The question has the Front at 3 and the rear at 6, does that mean that the queue is 3,4,5,6? With locations 4&5 being empty? can the queue go 3,2,1,0,6 ? this appears to be what the question is suggesting. So Join 56 would put add on at location 5 and Join 35 at location 4. Leave would move the front to 2, giving the answer 7 that they are looking for in 3.1 and Front 1, rear 4 in 3.2

    I had a look on the notes and on a couple of those pages and they all have the stacks increasing so an example like
    0,1,2,3,4,5
    ,2,4,6,7,
    Could have a start at 1 and end at 4 while
    0,1,2,3,4,5
    1,0,0,6,7,8
    Would be start 3, end 0

    Can anyone shed some light on it for me?

    Sean

    d
    Participant

    This queue implementation seems counter to any typical examples, which would normally increment the rear pointer as items are added and would therefore would be consistent with the front be 6 and the rear be 3, but swapping it around fits with the highlighted answers.

    In essence doing it either way is still using an array to implement a queue, but this example seems unnecessarily obfuscated if the goal is to demonstrate an understand of how queues work rather than an ability to comprehend poorly constructed code.

    To answer your specific query, the queue can work either way – indeed a queue could be implemented to fill only the odd array locations until ‘full’ and then the even locations. The underlying structure is not important in the operation of queues. However, I would question why anyone would use my bad example, and hope that the example above had a good rationale for not having a more expected implementation.

    Sean Stratton
    Participant

    Thanks, I was sure I had said this last week.

    I’ll just let the pupils know to look for the spaces as these separate beginning and end, I think think I’ll gloss over the odd and even thing 😉

    Sean

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.