Advertisement
dllbridge

Untitled

Sep 13th, 2023
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1.  
  2. /*
  3.  
  4. Methods Description
  5. ---------------------------
  6. push()  inserts an element at the back of the queue
  7. pop()   removes an element from the front of the queue
  8. front() returns the first element of the queue
  9. back()  returns the last element of the queue
  10. size()  returns the number of elements in the queue
  11. empty() returns true if the queue is empty
  12.  
  13. */
  14.  
  15. #include <iostream>
  16. #include    <queue>  // подключили библиотеку queue
  17. using namespace std;
  18.  
  19.  
  20.  
  21. ///////////////////////////////////////////////////////////////
  22. int main()
  23. {
  24.  
  25.  
  26.   queue<int> nums;                                           // create a queue of int
  27.  
  28.  
  29.   nums.push(1);                                              // push element into the queue
  30.   nums.push(2);
  31.   nums.push(3);
  32.  
  33.  
  34.   int front = nums.front();                                  // get the element at the front
  35.   cout << "First element: " << front << endl;
  36.  
  37.  
  38.   int back = nums.back();                                    // get the element at the back
  39.   cout << "Last element: " << back << endl;
  40.  
  41.   return 0;
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /*
  50.  
  51. ////////////////////////////////////////////////////////
  52. int main()
  53. {
  54.    
  55.   setlocale(LC_ALL,"rus");
  56.   queue <int> q;  // создали очередь q
  57.  
  58.   cout << "Пользователь, пожалуйста введите 7 чисел: " << endl;
  59.  
  60.   for(int h = 0; h < 7; h++)
  61.   {
  62.       int a;
  63.    
  64.       cin >> a;
  65.      
  66.       q.push(a);  // добавляем в очередь элементы
  67.   }
  68.  
  69.   cout << endl;
  70.   cout << "Первый элемент в очереди: " << q.front() << endl;  // выводим первый
  71.                                                                    // элемент очереди
  72.   q.pop();  // удаляем элемент из очереди
  73.    
  74.   cout << "Новый первый элемент (после удаления): " << q.front() << endl;
  75.    
  76.   if (!q.empty()) cout << "Очередь не пуста!";  // проверяем пуста ли очередь (нет)
  77.    
  78. return 0;
  79. }
  80.  
  81.  
  82.  
  83. */
  84.  
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement