Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. using namespace std;
  4.  
  5. //TABLICOWA REALIZACJA KOLEJKI
  6.  
  7. #define LIMIT 100
  8. int QUEUE[LIMIT];
  9. int first,last,size;
  10. void display()
  11. {
  12. for(int i=0;i<size;i++)
  13. {
  14. cout<<QUEUE[(first+i)%LIMIT]<<" ";
  15. }
  16. }
  17. void create()
  18. {
  19. first=0;
  20. last=LIMIT-1;
  21. size=0;
  22. }
  23. bool is_empty()
  24. {
  25. if(size==0)return true;
  26. else return false;
  27. }
  28. void insert(int x)
  29. {
  30. if(size==last)cout<<"OVERFLOW"<<endl;
  31. else
  32. {
  33. size++;
  34. last=(last+1)%LIMIT;
  35. QUEUE[last]=x;
  36. }
  37. display();
  38. }
  39. void First()
  40. {
  41. if(size==0)cout<<"QUEUE IS EMPTY!"<<endl;
  42. else
  43. cout<<QUEUE[first]<<endl;
  44. display();
  45. }
  46. void Delete()
  47. {
  48. if(size==0)cout<<"QUEUE IS EMPTY!"<<endl;
  49. else
  50. size=size-1;
  51. first=(first+1)%LIMIT;
  52. display();
  53. }
  54. int main()
  55. {
  56. cout<<"==================================="<<endl;
  57. cout<<"MENU"<<endl;
  58. cout<<"==================================="<<endl;
  59. cout<<"1. TWORZENIE KOLEJKI"<<endl;
  60. cout<<"2. SPRAWDZANIE, CZY KOLEJKA JEST PUSTA"<<endl;
  61. cout<<"3. WSTAWIANIE ZADANEGO ELEMENTU DO KOLEJKI"<<endl;
  62. cout<<"4. WYSWIETLANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
  63. cout<<"5. USUWANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
  64. cout<<"6. KONIEC PROGRAMU(KAZDY INNY KLAWISZ ROWNIEZ KONCZY PROGRAM)"<<endl;
  65. int command=0;
  66. cout<<endl;
  67. cout<<"PODAJ NUMER POLECENIA : ";
  68. cin>>command;
  69. while(command!=6)
  70. {
  71. if(command==1)
  72. {
  73. create();
  74. }
  75. else if(command==2)
  76. {
  77. if(is_empty())
  78. cout<<"KOLEJKA JEST PUSTA"<<endl;
  79. else
  80. cout<<"KOLEJKA NIE JEST PUSTA"<<endl;
  81.  
  82. }
  83. else if(command==3)
  84. {
  85. cout<<"PODAJ ELEMENT, KTORY CHCESZ WSTAWIC DO KOLEJKI: "<<endl;
  86. int x;
  87. cin>>x;
  88. insert(x);
  89. }
  90. else if(command==4)
  91. {
  92. First();
  93. }
  94. else if(command==5)
  95. {
  96. Delete();
  97. }
  98. else
  99. {
  100. break;
  101. }
  102. Sleep(1000);
  103. system("cls");
  104. cout<<"==================================="<<endl;
  105. cout<<"MENU"<<endl;
  106. cout<<"==================================="<<endl;
  107. cout<<"1. TWORZENIE KOLEJKI"<<endl;
  108. cout<<"2. SPRAWDZANIE, CZY KOLEJKA JEST PUSTA"<<endl;
  109. cout<<"3. WSTAWIANIE ZADANEGO ELEMENTU DO KOLEJKI"<<endl;
  110. cout<<"4. WYSWIETLANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
  111. cout<<"5. USUWANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
  112. cout<<"6. KONIEC PROGRAMU(KAZDY INNY KLAWISZ ROWNIEZ KONCZY PROGRAM)"<<endl<<endl;
  113. cout<<"PODAJ NUMER POLECENIA : ";
  114. cin>>command;
  115.  
  116. }
  117.  
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement