-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
86 lines (72 loc) · 1.9 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Queue.h"
#include "QueueArray.h"
#include "QueueList.h"
#include "MQueue.h"
#include <random>
int main()
{
//Creates 2 instances of Mqueue
Queue* MQarray = new QueueArray(60); // array
Queue* MQlist = new QueueList(); // link - list
srand(time(NULL));
int* randarray = new int[101];
//Printing of the random organs in the array
cout << "The randoms numbers are : " << endl;
for (int i = 0; i < 101; i++)
{
randarray[i] = rand() % 10000 + 1;
cout << randarray[i] << " ";
}
//Creating middle queue
MQueue* MQmid = new MQueue(MQarray, MQlist);
//Printing the organs in the MQ
cout << endl << "\nThe MQ numbers are : " << endl;
for (int i = 0; i < 51; i++)
{
if (MQarray->sizeQ != 59)
{
MQmid->MEnqueue(randarray[i]);
}
else
cout << " no space!!!!! " << endl;
}
//Showing the middle number
int middle = MQmid->Middle();
cout << " the middle number is : " << middle << endl;
//Priting the removing (2) numbers from the middle queue
cout << endl << "removing 2 numbers from the Queue : " ;
for (int i = 0; i < 2; i++)
{
int returnval = MQmid->MDequeue();
if (returnval == -1)
{
cout << endl << endl << "the Q is empty";
}
cout << returnval << " ";
}
//Priting the middle organ
middle = MQmid->Middle();
if (middle != -1)
{
cout << endl << "\nmid of MQ : " << middle << endl;
}
else
cout << endl << " Q is empty - No mid number " << endl;
//Enter the rest of the numbers
cout << endl << "\nThe numbers of MQ are :\n";
for (int i = 51; i < 101; i++)
{
if (MQarray->sizeQ != 60 - 1)
MQmid->MEnqueue(randarray[i]);
else
cout << endl << "The Queue is full";
}
//Priting the middle organ
middle = MQmid->Middle();
if (middle != -1)
{
cout << endl << "\nmid of MQ :" << middle << endl;
}
else
cout << endl << " Queue is empty ";
}