DataStructure for Elevator Mechanism

Viewed 50067

This question was asked to me during company interview - Which data-structure is efficient for Implementing Elevator Mechanism?

I am not able to find the efficient data-structure for it even after a lot of Googling.

I can think of Priority queue to Implement it.Is priority queue an efficient data structure or more efficient data structure is there for implementing Elevator Mechanism?

Thanks!

6 Answers

Consider you are the senior program developer, lift manufacture company approaches your team to do a program on lift operation with following constraints.

  1. Building has total 15 floors, and 4 underground floors for car parking
  2. Initially the lift starts from -4th floor and reaches the destination on customer wish
  3. Later the lift starts from its last position and reaches the destination
  4. If the lift operator press halt (eg. Press 2 to halt) the reaches to -4th floor from its last position. Sample output:
  5. Start
  6. Halt

1

Enter your destionation floor: 3 Lift starts…

-3

-1 0 1 2 3

Related