-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
132 lines (122 loc) · 3.36 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <queue>
/*
Task 1 - A program that adds to the queue X the size of N, the elements of the queue Y the size of K after the middle element
Task 2 - A program that removes the K-number of elements after the middle element of queue X of size N
*/
using namespace std;
int main()
{
system("chcp 1251");
short int choice=1;
while(choice!=0)
{
cout << "\n1 - Task 1 | 2 - Task 2 | 0 - Exit \n";
cin >> choice;
switch(choice)
{
case 1:
{
int a,n,k;
queue <int> x;
queue <int> y;
queue <int> z;
cout << "Enter the length of X queue: ";
cin >> n;
int l=n/2;
cout << "Enter the elements of X queue\n";
for(int i=1; i<=n; i++)
{
cout << "["<<i<<"]:";
cin >> a;
x.push(a);
}
cout << "Enter the length of Y queue: ";
cin >> k;
cout << "Enter the elements of Y queue\n";
for(int i=1; i<=k; i++)
{
cout << "["<<i<<"]:";
cin >> a;
y.push(a);
}
for(int i=1; i<=l; i++)
{
z.push(x.front());
if(!x.empty())
x.pop();
}
for(int i=l+1; i<=l+k; i++)
{
z.push(y.front());
if(!y.empty())
y.pop();
}
for(int i=l+k+1; i<=n+k; i++)
{
z.push(x.front());
if(!x.empty())
x.pop();
}
cout << "Result\n";
for(int i=1; i<=n+k; i++)
{
cout << z.front() << " ";
if(!z.empty())
z.pop();
}
}break;
case 2:
{
int a,n,k;
queue <int> x;
queue <int> y;
cout << "Enter the length of X queue: ";
cin >> n;
int l=n/2;
cout << "Enter the elements of X queue\n";
for(int i=1; i<=n; i++)
{
cout << "["<<i<<"]:";
cin >> a;
x.push(a);
}
cout << "Enter the count of elements after L to be deleted: ";
cin >> k;
if(!(0<=l+k && l+k <=n)){cout << "Error! The data entered does not satisfy the condition 0<=L+k<=N"; break;}
for(int i=1; i<=l; i++)
{
y.push(x.front());
if(!x.empty())
x.pop();
}
for(int i=l+1; i<=l+k; i++)
{
if(!x.empty())
x.pop();
}
for(int i=l+k+1; i<=n; i++)
{
y.push(x.front());
if(!x.empty())
x.pop();
}
cout << "Result\n";
for(int i=1; i<=n-k; i++)
{
cout << y.front() << " ";
if(!y.empty())
y.pop();
}
}break;
case 0:
{
cout << "Exit!"; return 0;
}
default:
cout << "Error! Enter "1" or "2" or "0"\n";
break;
}
}
return 0;
}