I have an array of 0,1 elements which each one corresponds to the buttons of a lift. How Can I prioritize the array to correspond to the calls from the highest index to lowest index? I means if the floor 0 and floor1 (index 0 and 1 in array) are called at the same time it firsts goes to floor 1 and then get back to floor0.
Thanks in advance.
You can implement various algorithms. Either you search for the request closest or most distant from the current position, or from floor 0, or for the direction with most requests above or below the current position, or however you want your elevator to behave.
For the search itself use a for loop, from the current position to the ends of your array, or through the entire array and remember the lowest/highest difference between the requested and current floor.