SHARE
TWEET

Untitled

a guest May 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. struct kolejka
  4. {
  5. const int n=7;
  6. int head=7;
  7. int tail=1;
  8. int tab[7];
  9. };
  10. bool empty(kolejka &q)
  11. {
  12. if (q.head==q.tail)
  13. {
  14. return true;
  15. }
  16. else
  17. {
  18. return false;
  19. }
  20. }
  21. void enqueue (kolejka &q, int x)
  22. {
  23. if (q.tail+1==q.head || q.head==1 && q.tail==q.n)
  24. {
  25. cout<<"pusta"<<endl;
  26. }
  27. else
  28.   {
  29.     q.tab[q.tail]=x;
  30.     if (q.tail==q.n)
  31.     {
  32.         q.tail=1;
  33.       }
  34.       else q.tail=q.tail+1;
  35.   }
  36. }
  37. int dequeue(kolejka &q)
  38. {
  39. if (empty(q))
  40.   {
  41.    cout<<"error"<<endl;
  42.    return -1;
  43.   }
  44. else
  45.  {
  46.   int x=q.tab[q.head];
  47. if (q.head==q.n)
  48. {
  49.     q.head=1;
  50.    
  51.  }
  52. else
  53. {
  54. q.head=q.head+1;
  55. }
  56. return x;
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. kolejka Q;
  63. enqueue(Q,1);
  64. enqueue(Q,2);
  65. enqueue(Q,3);
  66. enqueue(Q,4);
  67. enqueue(Q,5);
  68.  
  69. cout<<dequeue(Q)<<endl;
  70.  
  71. return 0;
  72. }
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
 
Top