Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RequestQueue.h@3:c3d716d6c6a7, 2015-03-26 (annotated)
- Committer:
- avinashr
- Date:
- Thu Mar 26 23:41:44 2015 +0000
- Revision:
- 3:c3d716d6c6a7
- Parent:
- 2:2cc70773996b
- Child:
- 4:95fe80130442
Logic completely implemented
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| avinashr | 1:4ec28912c9e7 | 1 | #include "mbed.h" |
| avinashr | 1:4ec28912c9e7 | 2 | |
| avinashr | 1:4ec28912c9e7 | 3 | #ifndef REQUESTQUEUE_H |
| avinashr | 1:4ec28912c9e7 | 4 | #define REQUESTQUEUE_H |
| avinashr | 1:4ec28912c9e7 | 5 | |
| avinashr | 2:2cc70773996b | 6 | class RequestQueue { |
| avinashr | 1:4ec28912c9e7 | 7 | |
| avinashr | 2:2cc70773996b | 8 | private : |
| avinashr | 2:2cc70773996b | 9 | int floorRequests[5]; |
| avinashr | 2:2cc70773996b | 10 | public : |
| avinashr | 2:2cc70773996b | 11 | RequestQueue() { |
| avinashr | 2:2cc70773996b | 12 | for(int i=0;i<5;i++) |
| avinashr | 2:2cc70773996b | 13 | floorRequests[i] = 0; |
| avinashr | 2:2cc70773996b | 14 | } |
| avinashr | 1:4ec28912c9e7 | 15 | |
| avinashr | 2:2cc70773996b | 16 | void add(int); |
| avinashr | 2:2cc70773996b | 17 | void remove(int); |
| avinashr | 2:2cc70773996b | 18 | int isRequested (int); |
| avinashr | 3:c3d716d6c6a7 | 19 | int isForwardRequested (int); |
| avinashr | 3:c3d716d6c6a7 | 20 | int isReverseRequested (int); |
| avinashr | 1:4ec28912c9e7 | 21 | }; |
| avinashr | 1:4ec28912c9e7 | 22 | |
| avinashr | 2:2cc70773996b | 23 | void RequestQueue::add (int i){ |
| avinashr | 3:c3d716d6c6a7 | 24 | floorRequests[i-1] = 1; |
| avinashr | 2:2cc70773996b | 25 | } |
| avinashr | 2:2cc70773996b | 26 | |
| avinashr | 2:2cc70773996b | 27 | void RequestQueue::remove (int i){ |
| avinashr | 3:c3d716d6c6a7 | 28 | floorRequests[i-1] = 0; |
| avinashr | 2:2cc70773996b | 29 | } |
| avinashr | 2:2cc70773996b | 30 | |
| avinashr | 2:2cc70773996b | 31 | int RequestQueue::isRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 32 | return floorRequests[i-1]; |
| avinashr | 3:c3d716d6c6a7 | 33 | } |
| avinashr | 3:c3d716d6c6a7 | 34 | |
| avinashr | 3:c3d716d6c6a7 | 35 | int RequestQueue::isForwardRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 36 | for(int j = i; j<5; j++){ |
| avinashr | 3:c3d716d6c6a7 | 37 | if(floorRequests[j] == 1) |
| avinashr | 3:c3d716d6c6a7 | 38 | return 1; |
| avinashr | 3:c3d716d6c6a7 | 39 | } |
| avinashr | 3:c3d716d6c6a7 | 40 | return 0; |
| avinashr | 3:c3d716d6c6a7 | 41 | } |
| avinashr | 3:c3d716d6c6a7 | 42 | |
| avinashr | 3:c3d716d6c6a7 | 43 | int RequestQueue::isReverseRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 44 | for(int j = 0; j<i-1; j++){ |
| avinashr | 3:c3d716d6c6a7 | 45 | if(floorRequests[j] == 1) |
| avinashr | 3:c3d716d6c6a7 | 46 | return 1; |
| avinashr | 3:c3d716d6c6a7 | 47 | } |
| avinashr | 3:c3d716d6c6a7 | 48 | return 0; |
| avinashr | 2:2cc70773996b | 49 | } |
| avinashr | 2:2cc70773996b | 50 | |
| avinashr | 1:4ec28912c9e7 | 51 | #endif |