fork download
  1. #include<stdio.h>
  2. #define Queue_size 10
  3.  
  4. int Queue[Queue_size];
  5. int in,out;
  6. int count;
  7. void initialze() {
  8. in = 0; out = 0; count =0;
  9. }
  10. void enterq(int val) {
  11. if(count<Queue_size ){
  12. in++;
  13. if(in==Queue_size) in =0;
  14. count++;
  15. Queue[in] = val;
  16. }else printf("Queue full\n");
  17. }
  18. int removeq(void) {
  19. if(count>0) {
  20. out++;
  21. if(out==Queue_size) out =0;
  22. count--;
  23. return Queue[out];
  24. }else {
  25. printf("Queue empty\n");
  26. return -1;
  27. }
  28. }
  29. void display(void) {
  30. int i;
  31. for(i=1;i<=Queue_size;i++){
  32. printf("\n%d\n",Queue[i]);
  33. if(count == i) break;
  34. }
  35. }
  36.  
  37. main() {
  38. int mode,id;
  39. initialze();
  40. mode = 1;
  41. while(mode) {
  42. printf("queue process ? enter(1) or remove(0) ="); scanf("%d",&mode);
  43. if(mode==1) {
  44. printf("? id = "); scanf("%d",&id);
  45. enterq(id);
  46. }else if(mode==0) {
  47. id = removeq();
  48. if(id>0) printf("id = %d was removed\n",id);
  49. }
  50. display();
  51. printf("?continue(1) or quit(0) = "); scanf("%d",&mode);
  52. }
  53. return 0;
  54. }
  55.  
  56.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty