I'm practising with data structures at the moment, I came across this question at one of the online tests I was taking and it confused me. Can anyone clarify this for me because I couldn't answer it and I started hesitating my knowledge.
Question:
Assume that the underpinning data structure for the implementation of queues is an array. How will you guarantee that an empty queue (array) is not taken mistakenly for a full one.
If you implement a queue using an array the queue's max size will be the size of the array, but you can't tell if the queue is empty or full just using the size of the array cause is static, you need to keep a counter that increases or decreases depending if you add or remove elements to the queue, when the counter is equal to the length of the array the queue if full, you could also validate if the queue is empty when all the positions in the array are null, but that'll consume more time that having just a counter, I guess you actually know all this but to me seems like the question is referring to that.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments