File tree 1 file changed +61
-0
lines changed
1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ // { Driver Code Starts
2
+ // Initial Template for C++
3
+
4
+ #include < bits/stdc++.h>
5
+ using namespace std ;
6
+
7
+ // } Driver Code Ends
8
+ // function Template for C++
9
+
10
+ // Function to reverse the queue.
11
+ class Solution
12
+ {
13
+ public:
14
+ queue<int > rev (queue<int > q)
15
+ {
16
+ // add code here.
17
+ stack<int > s;
18
+
19
+ while (!q.empty ()) {
20
+ s.push (q.front ());
21
+ q.pop ();
22
+ }
23
+
24
+ queue<int > rq;
25
+
26
+ while (!s.empty ()) {
27
+ rq.push (s.top ());
28
+ s.pop ();
29
+ }
30
+
31
+ return rq;
32
+ }
33
+ };
34
+
35
+
36
+ // { Driver Code Starts.
37
+ int main ()
38
+ {
39
+ int test;
40
+ cin>>test;
41
+ while (test--)
42
+ {
43
+ queue<int > q;
44
+ int n, var;
45
+ cin>>n;
46
+ while (n--)
47
+ {
48
+ cin>>var;
49
+ q.push (var);
50
+ }
51
+ Solution ob;
52
+ queue<int > a=ob.rev (q);
53
+ while (!a.empty ())
54
+ {
55
+ cout<<a.front ()<<" " ;
56
+ a.pop ();
57
+ }
58
+ cout<<endl;
59
+ }
60
+ }
61
+ // } Driver Code Ends
You can’t perform that action at this time.
0 commit comments