-
Notifications
You must be signed in to change notification settings - Fork 0
/
MQueue.cpp
53 lines (47 loc) · 1.19 KB
/
MQueue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "MQueue.h"
#include "Queue.h"
//C'tor
MQueue::MQueue(Queue* QueueArray, Queue* QueueList)
{
this->QueueArray = QueueArray;
this->QueueList = QueueList;
changeMid = false;
}
//Adds a new figure x of general type to the end of the middle turn
void MQueue::MEnqueue(int value)
{
this->QueueList->Enqueue(value);
if (changeMid)
{
int removeItem = this->QueueList->Dequeue();
this->QueueArray->Enqueue(removeItem);
}
cout << value << " ";
changeMid = (this->QueueArray->sizeQ + this->QueueList->sizeQ) % 2 == 0;
}
//Removes the figure at the top of the middle queue and returns it
int MQueue::MDequeue()
{
int removeItem;
if (this->QueueArray->IsEmpty())
{
removeItem = this->QueueList->Dequeue();
}
else
{
removeItem = this->QueueArray->Dequeue();
}
changeMid = (this->QueueArray->sizeQ + this->QueueList->sizeQ) % 2 == 1 &&
this->QueueList->sizeQ > 2;
if (changeMid)
{
int DeItem = this->QueueList->Dequeue();
this->QueueArray->Enqueue(DeItem);
}
return removeItem;
}
//Returns the data that is in the middle of the middle queue without removing it from the queue
int MQueue::Middle()
{
return this->QueueList->Top();
}