SHARE
TWEET

Untitled

a guest May 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 choice;
  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 >> choice;
  59.         switch (choice) {
  60.         case 1: Insert();
  61.             break;
  62.         case 2: Delete();
  63.             break;
  64.         case 3: Display();
  65.             break;
  66.         case 4:
  67.             cout << "Wyjscie" << endl;
  68.             break;
  69.         default:
  70.             cout << "Zly wybor" << endl;
  71.         }
  72.     } while (choice != 4);
  73.     return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top