Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void add(int input);
  4. void show();
  5. void del();
  6. bool isFull();
  7. bool isEmpty();
  8.  
  9.  
  10. const int len=5;
  11. int queue[len];
  12. int rear=0,front=0;
  13.  
  14. int main(){
  15. add(1);
  16. add(2);
  17. add(3);
  18. add(4);
  19. add(5);
  20. add(6);
  21. add(7);
  22. add(8);
  23. del();
  24. del();
  25. del();
  26. add(1);
  27. add(2);
  28. add(3);
  29. }
  30.  
  31. void add(int input){
  32. if(isFull()) {
  33. printf("Full!!\n");
  34. return;
  35. }
  36. printf("ADD:%d\n",input);
  37. queue[rear++]=input;
  38. show();
  39. }
  40.  
  41. void del(){
  42. if(isEmpty()){
  43. printf("Empty!!\n");
  44. return;
  45. }
  46. printf("DEL:%d\n",queue[front]);
  47. queue[front++]=0;
  48. show();
  49. }
  50.  
  51. bool isFull(){
  52. return front==0 && rear==len+1;
  53. }
  54.  
  55. bool isEmpty(){
  56. return rear==front;
  57. }
  58.  
  59. void show(){
  60. printf("SHOW:[Front=%d]",front);
  61. for(int i=front;i<rear;i++){
  62. printf("%d ",queue[i]);
  63. }
  64. printf("[Rear=%d]\n",rear);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement