Advertisement
Zuneve

3 cpp

Aug 29th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. using namespace std;
  4. int main() {
  5. int n, llo, kk;
  6. deque <int> a;
  7. cin >> n;
  8. while (n--) {
  9. cin >> llo;
  10. if (llo==1) {
  11. cin >> kk;
  12. a.push_front(kk);
  13. } else if (llo==2) {
  14. cin >> kk;
  15. a.push_back(kk);
  16. } else if (llo==3) {
  17. kk=a.front();
  18. cout << kk << " ";
  19. a.pop_front();
  20. } else {
  21. kk=a.back();
  22. cout << kk << " ";
  23. a.pop_back();
  24. }
  25. }
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement