Group PAG
/
PAG-CourseWork-NicksEdits
Minor fixes
Fork of Coursework by
Queue.cpp@42:4e0a96b52e65, 2017-05-03 (annotated)
- Committer:
- pburtenshaw
- Date:
- Wed May 03 13:30:38 2017 +0000
- Revision:
- 42:4e0a96b52e65
- Child:
- 43:4ddc392dd0cc
queue started
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pburtenshaw | 42:4e0a96b52e65 | 1 | #include "Queue.h" |
pburtenshaw | 42:4e0a96b52e65 | 2 | |
pburtenshaw | 42:4e0a96b52e65 | 3 | |
pburtenshaw | 42:4e0a96b52e65 | 4 | void Queue::Queue(){ |
pburtenshaw | 42:4e0a96b52e65 | 5 | front = 0; |
pburtenshaw | 42:4e0a96b52e65 | 6 | back = 0; |
pburtenshaw | 42:4e0a96b52e65 | 7 | count = 0; |
pburtenshaw | 42:4e0a96b52e65 | 8 | } |
pburtenshaw | 42:4e0a96b52e65 | 9 | static void Queue::add(Queue q, int i) { |
pburtenshaw | 42:4e0a96b52e65 | 10 | if ((q.back == {size -1) && q.front == 0) || (q.back - q.front = 1)) { |
pburtenshaw | 42:4e0a96b52e65 | 11 | // buffer is full, delete oldies |
pburtenshaw | 42:4e0a96b52e65 | 12 | // put data in front |
pburtenshaw | 42:4e0a96b52e65 | 13 | // front++ back ++ |
pburtenshaw | 42:4e0a96b52e65 | 14 | } else { |
pburtenshaw | 42:4e0a96b52e65 | 15 | q.back = q.back + 1; |
pburtenshaw | 42:4e0a96b52e65 | 16 | q.data [q.back] = i; |
pburtenshaw | 42:4e0a96b52e65 | 17 | } |
pburtenshaw | 42:4e0a96b52e65 | 18 | } |
pburtenshaw | 42:4e0a96b52e65 | 19 | |
pburtenshaw | 42:4e0a96b52e65 | 20 | static int Queue::remove(Queue q) { |
pburtenshaw | 42:4e0a96b52e65 | 21 | if (q.back < 0) { |
pburtenshaw | 42:4e0a96b52e65 | 22 | printf("Queue remove ERROR"); |
pburtenshaw | 42:4e0a96b52e65 | 23 | return(-1); |
pburtenshaw | 42:4e0a96b52e65 | 24 | } else { |
pburtenshaw | 42:4e0a96b52e65 | 25 | int temporary = q.data[0]; |
pburtenshaw | 42:4e0a96b52e65 | 26 | q.back = q.back -1; |
pburtenshaw | 42:4e0a96b52e65 | 27 | return (temporary); |
pburtenshaw | 42:4e0a96b52e65 | 28 | } |
pburtenshaw | 42:4e0a96b52e65 | 29 | } |