Advertisement
Guest User

Untitled

a guest
May 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define SIZE 5
  4. int queue[SIZE], n = SIZE, front = -1, rear = -1;
  5.  
  6. bool isfull() {
  7.     return rear == n - 1;
  8. }
  9.  
  10. void Insert() {
  11.     int val;
  12.     if (isfull())
  13.         cout << "Kolejka przepelniona" << endl;
  14.     else {
  15.         if (front == -1)
  16.             front = 0;
  17.         cout << "Wporawdz element do listy : ";
  18.         cin >> val;
  19.         rear++;
  20.         queue[rear] = val;
  21.     }
  22. }
  23.  
  24. bool isEmpty() {
  25.     return front == -1 || front > rear;
  26. }
  27.  
  28. void Delete() {
  29.     if (isEmpty()) {
  30.         cout << "Brak elementow w kolejce" << endl;
  31.         return;
  32.     }
  33.     else {
  34.         cout << "Element usuwany : " << queue[front] << endl;
  35.         front++;;
  36.     }
  37. }
  38.  
  39. void Display() {
  40.     if (front == -1)
  41.         cout << "Kolejka jest pusta" << endl;
  42.     else {
  43.         cout << "Elementy kolejki : ";
  44.         for (int i = front; i <= rear; i++)
  45.             cout << queue[i] << " ";
  46.         cout << endl;
  47.     }
  48. }
  49.  
  50. int main() {
  51.     int ch;
  52.     do {
  53.         cout << endl << "1) Wprowadz element do kolejki" << endl;
  54.         cout << "2) Usun element z kolejki" << endl;
  55.         cout << "3) Wyswietl elementy kolejki" << endl;
  56.         cout << "4) Wyjscie" << endl;
  57.         cout << "Wybierz opcje : ";
  58.         cin >> ch;
  59.         switch (ch) {
  60.         case 1: Insert();
  61.             break;
  62.         case 2: Delete();
  63.             break;
  64.         case 3: Display();
  65.             break;
  66.         case 4: cout << "Wyjscie" << endl;
  67.             break;
  68.         default: cout << "Zly wybor" << endl;
  69.         }
  70.     } while (ch != 4);
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement