Search code examples
data-structuresqueuestack

Which Data structure is suitable queue or stack?


I am given a task to develop an application that will manage the appointment of patients coming for treatment. There can be two types of patients called normal patients and emergency patients. The system will take information of every patient and decide the turn of patient on the basis of type of patient.

If the patient will be from normal category, it will take appointment on the basis of arrival while the emergency patient will take appointment early than normal patients. All normal and emergency patients will be added into same system but appointment will be given differently. Every emergency patient will get appointment immediately.

Which data structure from Stack and Queue will be most efficient choice for the development of required application.

Note: You are not allowed to use any other data structures like priority queue and double ended queue

According to me, queue is a better option for calling normal patients because this follows FIFO. But how to deal with emergency patients without using priority queue


Solution

  • Are you prohibited from using two queues ? If not use two one for emergency patients the other for regular patients.