This is a solution to the barber shop problem using a queue data structure. The barber shop problem is a classic synchronization problem. The problem is that there is a barber shop with a waiting room and a barber chair. There are n chairs in the waiting room. If there are no customers to be served, the barber goes to sleep. If a customer enters the barber shop and all chairs are occupied, then the customer leaves the shop. If the barber is busy, but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber.
- getValues() - This function gets the number of customers and chairs from the user.
- clr() - This function clears the output.
- start() - This function starts the simulation.
- sleep() - This function is used to delay the execution of the code.
- FifoQueue - This class is used to create a queue data structure.
- enqueue() - This method adds an element to the queue.
- dequeue() - This method removes an element from the queue.
- size() - This method returns the size of the queue.
- isEmpty() - This method checks if the queue is empty.
- Enter the number of customers. e.g. 1 2 3 4 5 6 7 8 9 10
- Enter the number of chairs. e.g. 7
Note: Purpose of this project only visualizing the process. I didn't use any data structure or algorithm except FifoQueue
. I just used the basic javascript and html. I will try to implement the data structure and algorithm in the future. If you have any suggestion or question please comment below. Thank you for reading.