# implementing simple elvator algoirthm

I want to implement simple elevator algoirthm.

people in different floors orders the elevator and the destination floor they want to get to (so you get a {from,to} alert from different floors).

So I got a simple strightforward solution :

once elevator start going in specific direction (lets say up) it will continue doing so , and serve all request of ppl want to go up (only if at the time they were made they were from higher floor in respect to the elevator) until serving the last one. all the request will be kept in an array, so on each floor you can check if someone wants to go on the same current direction.

In addition ill save in two vars (on for up direction and one for down direction) the highest and lowest points of request - hight floor that somebody wants to go up from there , and lowest floor that sombody want to get to lower floors from there - and the elevator allways will be travling between these two points picking all the ppl that want to go on the same direction.

Does this solution make sense/work ? is there something as simple that make more sense?

I saw some priorities queue suggestions while searching in google but didnt really understand what the need of them ..

• Priority queues are used when you want your elevator to serve the passenger whose floor is the closest to the current one first. Mar 26 '16 at 22:23
• Did you do any research? There's been a lot of work done in this area over the years. IIRC, Knuth took time off to study exactly this topic. Mar 27 '16 at 2:10
• One thing to consider would be elevator capacity. Timing gets interesting if not only time to enter/leave depends on occupancy, but also movement (in persons, if not in kilograms). Also, consider one person going up to some floor $f-1$, and one down from $f$ to $f-1$: shall the elevator stop at $f-1$ twice? (How about serving odd floors going up, and even floors going down? (More reasonable with complementary elevators side by side.) (Does floor 13 exist?)) I wonder what they are using in the vertical ghettos of, say, Hong Kong. (Please use a spelling checker and correct the title, too.) Mar 27 '16 at 3:48