E x Enqueue x in the queue and print the new size of the queue.
D : Dequeue from the queue and print the element that is deleted and the new size of the queue separated by space. If there is no element in the queue then print 1 in place of deleted element.
Since Micro is new with queue data structure, he need your help.
Input


5
E 2
D
D
E 3
D

Output


1
2 0
-1 0
1
3 0

Solution


#include <iostream>
using namespace std;
int main()
{
int size,p,x,f=0,r=0,s[100];
cin>>size;
char a;
for(int i=0;i<size;i++)
{
cin>>a;
if(a=='E')
{cin>>x;
s[r]= x;
r=r+1;
cout<<r-f<<endl;
}
else if(a=='D'){
if(f==r)
{cout<<-1<<" "<<0<<endl;}
else
{
cout<<s[f++]<<" "<<r-f-1<<endl;
}
}
}
return 0;

}





if you have any problem in this code, take a screenshot and contact with Rishabh Chaubey .

Post a Comment

Previous Post Next Post