-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path12 QueueImplementation.cpp
More file actions
76 lines (64 loc) · 1.7 KB
/
12 QueueImplementation.cpp
File metadata and controls
76 lines (64 loc) · 1.7 KB
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
/*
Write a program to create the queue of N elements in increasing order. Size of the queue should be greater than 2 and less than equal to 10. All the elements of the queue should be in increasing order. Element will not inserted in the queue if it will not follow the above condition.
Input Format
Your program should take the 2 types of inputs. First will represent the number of elements in the queue and second should insert the elements. If the entered element will not be in the increasing order then it will not inserted. If the size of the queue will not be in the mentioned range then it should display the message “Invalid size” with taking any elements for input.
Constraints
Size (N) of the queue should be 2 < N <= 10.
All the elements should be in increasing order.
Output Format
Your program should display the elements of the queue from front to rear. But if the size will be invalid then display the mentioned message.
Sample Input 0
3
2
1
3
4
Sample Output 0
2
3
4
Sample Input 1
2
Sample Output 1
Invalid size
*/
#include <iostream>
#include<queue>
using namespace std;
queue<int>task ;
int main()
{
int n;
cin>>n;
int count=0;
if(n>2 && n<=10)
{
int data;
cin>>data;
count++;
task.push(data);
for(int i=1;i<10;i++)
{
if(count==n)
{
break;
}
cin>>data;
if(data>task.front())
{
task.push(data);
count++;
}
}
while(!task.empty())
{
cout<<task.front()<<endl;
task.pop();
}
}
else
{
cout<<"Invalid size";
}
return 0;
}