Advertisement
nicuvlad76

Untitled

Jan 12th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. ///coada alocata static
  2. #include <bits/stdc++.h>
  3. #define N 10001
  4. using namespace std;
  5. struct Coada
  6. {
  7. int q[N];
  8. int pr,ul;
  9. void Init(){pr=0; ul=-1;}
  10. int Empty(){return pr>ul;}
  11. void Push(int x){q[++ul]=x;}
  12. void Pop(){if(!Empty()) pr++;}
  13. int Front(){return q[pr];}
  14. };
  15.  
  16. int main()
  17. {
  18. int n,x;
  19. Coada a;
  20. char s[7];
  21. a.Init();
  22. cin>>n;
  23. for(int i=1;i<=n;i++)
  24. {
  25. cin>>s;
  26. if(strcmp(s,"push")==0) {cin>>x;a.Push(x);}
  27. else if(strcmp(s,"pop")==0) a.Pop();
  28. else
  29. {
  30. if(!a.Empty())cout<<a.Front()<<"\n";
  31. }
  32. }
  33. return 0;
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement