cavaman

6-7.1

Jun 10th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <list>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool clearQue(queue<int>& cque);
  9. void queIsEmpty(queue<int>& eque);
  10. void printQue(queue<int> pque);
  11. bool pasteQue(queue<int>& inque);
  12. void extractQue(queue<int>& fromque, int& el);
  13. void goToList(queue<int>& que, list<int>& lis);
  14. void printList(list<int> plis);
  15.  
  16. int main()
  17. {
  18.     setlocale(LC_ALL, "");
  19.     queue<int> que;
  20.     list<int> lis;
  21.     vector<int> vec;
  22.     int ext_el, first, last;
  23.     for (int i = 0; i < 5; i++)
  24.     {
  25.         int el;
  26.         cin >> el;
  27.         que.push(el);
  28.     }
  29.     //printQue(que);
  30.     goToList(que, lis);
  31.     first = lis.front();
  32.     last = lis.back();
  33.     cout << "в) ";
  34.     printList(lis);
  35.     cout << "Первое звено списка - " << first << ", последнее звено списка - " << last;
  36. }
  37.  
  38. bool clearQue(queue<int>& cque)
  39. {
  40.     if (cque.empty())
  41.         return true;
  42.     for (int i = cque.size(); i > 0; i--)
  43.     {
  44.         cque.front();
  45.         cque.pop();
  46.     }
  47.     return true;
  48. }
  49.  
  50. void queIsEmpty(queue<int>& eque)
  51. {
  52.     if (eque.empty())
  53.         cout << "\nОчередь пустая";
  54.     else cout <<  "\nОчередь не пустая";
  55. }
  56.  
  57. void printQue(queue<int> pque)
  58. {
  59.     while (!pque.empty())
  60.     {
  61.         int el = pque.front();
  62.         pque.pop();
  63.         cout << el << " ";
  64.     }
  65. }
  66.  
  67. bool pasteQue(queue<int>& inque)
  68. {
  69.     cout << "\nЭлемент для вставки: ";
  70.     int el;
  71.     cin >> el;
  72.     inque.push(el);
  73.     return true;
  74. }
  75.  
  76. void extractQue(queue<int>& fromque, int& el)
  77. {
  78.     el = fromque.front();
  79.     fromque.pop();
  80. }
  81.  
  82. void goToList(queue<int>& copque, list<int>& coplis)
  83. {
  84.     while (!copque.empty())
  85.     {
  86.         coplis.push_front(copque.front());
  87.         copque.pop();
  88.     }
  89. }
  90.  
  91. void printList(list<int> plis)
  92. {
  93.     while (!plis.empty())
  94.     {
  95.         cout << plis.front() << " ";
  96.         plis.pop_front();
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment