Giter VIP home page Giter VIP logo

sauravhathi / sleeping-barber Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 68 KB

This is a solution to the barber shop problem using a queue data structure. The barber shop problem is a classic synchronization problem. #lpu

Home Page: https://sauravhathi.github.io/sleeping-barber/

License: MIT License

HTML 49.39% JavaScript 50.61%
lpu operating-system sauravhathi semaphore sleeping-barber lovely-professional-university

sleeping-barber's Introduction

Barber Shop Problem

DEMO

Screenshot

HomePage

image

Input

image

Simulation Output

image

When No Customer

image

Description

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.

Functions

  • 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.

Classes

  • FifoQueue - This class is used to create a queue data structure.

Methods

  • 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.

How to use

  • 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.

sleeping-barber's People

Contributors

sauravhathi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.