Set - 3

Question 11 :

What does isEmpty() member method determines?

Answer :

isEmpty() checks if the stack has at least one element. This method is called by Pop() before retrieving and returning the top element.


Question 12 :

What is a queue ?

Answer :

A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position.


Question 13 :

What is the relationship between a queue and its underlying array?

Answer :

Data stored in a queue is actually stored in an array. Two indexes, front and end will be used to identify the start and end of the queue.

When an element is removed front will be incremented by 1. In case it reaches past the last index available it will be reset to 0. Then it will be checked with end. If it is greater than end queue is empty.

When an element is added end will be incremented by 1. In case it reaches past the last index available it will be reset to 0. After incrementing it will be checked with front. If they are equal queue is full.


Question 14 :

Which process places data at the back of the queue?

Answer :

Enqueue is the process that places data at the back of the queue.


Question 15 :

Why is the isEmpty() member method called?

Answer :

The isEmpty() member method is called within the dequeue process to determine if there is an item in the queue to be removed i.e. isEmpty() is called to decide whether the queue has at least one element. This method is called by the dequeue() method before returning the front element.