Advertisement
momo2345

queue push and pop

Aug 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. queue<int>_push(int arr[],int n);
  6.  
  7.  
  8. void _pop(queue<int>s);
  9.  
  10.  
  11.  // } Driver Code Ends
  12.  
  13.  
  14. //User function Template for C++
  15.  
  16.  
  17. //User function Template for C++
  18.  
  19. queue<int>_push(int arr[],int n)
  20. {
  21.     queue<int>p;
  22.    //return a queue with all elements of arr inserted in it
  23.    for(int i=0;i<n;i++)
  24.    p.push(arr[i]);
  25.    return p;
  26. }
  27.  
  28. void _pop(queue<int>s)
  29. {
  30.     //print front and dequeue for each element until it becomes empt
  31.      while(!s.empty()){
  32.        cout<<s.front()<<" ";
  33.        s.pop();}
  34.  
  35. }
  36.  
  37. // { Driver Code Starts.
  38.  
  39. int main() {
  40.     int t;
  41.     cin>>t;
  42.     while(t--)
  43.     {
  44.         int n;
  45.         cin>>n;
  46.         int arr[n];
  47.         for(int i=0;i<n;i++)
  48.         cin>>arr[i];
  49.         queue<int>mys=_push(arr,n);
  50.         _pop(mys);
  51.         cout<<endl;
  52.        
  53.        
  54.        
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement