Advertisement
Bassel_11

Untitled

Dec 19th, 2022
717
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 1 0
  1. //⣿⣿⣿⣿⣯⣿⣿⠄⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠈⣿⣿⣿⣿⣿⣿⣆⠄
  2. //⢻⣿⣿⣿⣾⣿⢿⣢⣞⣿⣿⣿⣿⣷⣶⣿⣯⣟⣿⢿⡇⢃⢻⣿⣿⣿⣿⣿⢿⡄
  3. //⠄⢿⣿⣯⣏⣿⣿⣿⡟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣧⣾⢿⣮⣿⣿⣿⣿⣾⣷
  4. //⠄⣈⣽⢾⣿⣿⣿⣟⣄⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣝⣯⢿⣿⣿⣿⣿
  5. //⣿⠟⣫⢸⣿⢿⣿⣾⣿⢿⣿⣿⢻⣿⣿⣿⢿⣿⣿⣿⢸⣿⣼⣿⣿⣿⣿⣿⣿⣿
  6. //⡟⢸⣟⢸⣿⠸⣷⣝⢻⠘⣿⣿⢸⢿⣿⣿⠄⣿⣿⣿⡆⢿⣿⣼⣿⣿⣿⣿⢹⣿
  7. //⡇⣿⡿⣿⣿⢟⠛⠛⠿⡢⢻⣿⣾⣞⣿⡏⠖⢸⣿⢣⣷⡸⣇⣿⣿⣿⢼⡿⣿⣿
  8. //⣡⢿⡷⣿⣿⣾⣿⣷⣶⣮⣄⣿⣏⣸⣻⣃⠭⠄⠛⠙⠛⠳⠋⣿⣿⣇⠙⣿⢸⣿
  9. //⠫⣿⣧⣿⣿⣿⣿⣿⣿⣿⣿⣿⠻⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣹⢷⣿⡼⠋
  10. //⠄⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣿⣿⣿⠄⠄
  11. //⠄⠄⢻⢹⣿⠸⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣼⣿⣿⣿⣿⡟⠄⠄
  12. //⠄⠄⠈⢸⣿⠄⠙⢿⣿⣿⣹⣿⣿⣿⣿⣟⡃⣽⣿⣿⡟⠁⣿⣿⢻⣿⣿⢿⠄⠄
  13. //⠄⠄⠄⠘⣿⡄⠄⠄⠙⢿⣿⣿⣾⣿⣷⣿⣿⣿⠟⠁⠄⠄⣿⣿⣾⣿⡟⣿⠄⠄
  14. //⠄⠄⠄⠄⢻⡇⠸⣆⠄⠄⠈⠻⣿⡿⠿⠛⠉⠄⠄⠄⠄⢸⣿⣇⣿⣿⢿⣿⠄⠄⠀
  15.  
  16. //          Vengeance
  17. #include <bits/stdc++.h>
  18. #define ll long long
  19. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  20. #define ln cout<<endl;
  21. using namespace std;
  22.  
  23. const int MAX_SIZE = 100;
  24.  
  25. class Queue {
  26.  private:
  27.   int items[MAX_SIZE];
  28.   int front;
  29.   int rear;
  30.   int count;
  31.  
  32.  public:
  33.   Queue() {
  34.     front = 0;
  35.     rear = MAX_SIZE - 1;
  36.     count = 0;
  37.   }
  38.  
  39.   int length() {
  40.     return count;
  41.   }
  42.  
  43.   void enqueue(int element) {
  44.     rear = (rear + 1) % MAX_SIZE;
  45.     items[rear] = element;
  46.     count++;
  47.   }
  48.  
  49.   int dequeue() {
  50.     int element = items[front];
  51.     front = (front + 1) % MAX_SIZE;
  52.     count--;
  53.     return element;
  54.   }
  55.  
  56.   int search_queue(int item) {
  57.     for (int i = 0; i < count; i++) {
  58.       int index = (front + i) % MAX_SIZE;
  59.       if (items[index] == item) {
  60.         return i;
  61.       }
  62.     }
  63.     return -1;
  64.   }
  65. };
  66.  
  67. int main() {
  68.   Queue q;
  69.   q.enqueue(1);
  70.   q.enqueue(2);
  71.   q.enqueue(3);
  72.   cout << q.length() << endl;
  73.   cout << q.dequeue() << endl;
  74.   cout << q.search_queue(2) << endl;
  75.   return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement