Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. std::vector<int> singleElevatorSystem (int inputFloors[], int size, int currentFloor, string direction) {
  2. std::vector<int> High, Low;
  3.  
  4. for (int i = 0; i < size; i++) {
  5. if (currentFloor < inputFloors[i]) {
  6. High.push_back (inputFloors[i]);
  7. } else if (currentFloor > inputFloors[i]) {
  8. Low.push_back (inputFloors[i]);
  9. }
  10. }
  11.  
  12. std::sort (High.begin(), High.end());
  13. std::sort (Low.begin(), Low.end());
  14.  
  15. if (direction.compare("UP") == 0) {
  16. High.insert(High.end(), Low.rbegin(), Low.rend());
  17. return High;
  18. } else if (direction.compare("DOWN") == 0) {
  19. std::reverse (Low.begin(), Low.end());
  20. Low.insert (Low.end(), High.begin(), High.end());
  21. return Low;
  22. }
  23. }
  24.  
  25. int main () {
  26. int inputFloors[] = {5, 2, 9, 3, 8, 1};
  27. int currentFloor = 6;
  28. //string direction("UP");
  29. string direction("DOWN");
  30.  
  31. std::vector<int> outputFloors = singleElevatorSystem (inputFloors, 6, currentFloor, direction);
  32. std::cout << "Elevator will stop at requested floors in sequence : ";
  33. for (int i = 0; i < 6; i++) {
  34. std::cout << outputFloors.at(i) << " ";
  35. }
  36.  
  37. std::cin.get();
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement