fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8.  
  9.  
  10. #include <stdio.h>
  11. #define SIZE 5
  12.  
  13. int queue[SIZE];
  14. int front = -1, rear = -1;
  15.  
  16. // Enqueue function
  17. void enqueue(int value) {
  18. if (rear == SIZE - 1)
  19. printf("Queue is Full\n");
  20. else {
  21. if (front == -1) front = 0;
  22. rear++;
  23. queue[rear] = value;
  24. printf("%d inserted\n", value);
  25. }
  26. }
  27.  
  28. // Dequeue function
  29. void dequeue() {
  30. if (front == -1 || front > rear)
  31. printf("Queue is Empty\n");
  32. else {
  33. printf("%d deleted\n", queue[front]);
  34. front++;
  35. }
  36. }
  37.  
  38. // Display function
  39. void display() {
  40. if (front == -1 || front > rear)
  41. printf("Queue is Empty\n");
  42. else {
  43. printf("Queue: ");
  44. for (int i = front; i <= rear; i++)
  45. printf("%d ", queue[i]);
  46. printf("\n");
  47. }
  48. }
  49.  
  50. // Main function
  51. int main() {
  52. enqueue(10);
  53. enqueue(20);
  54. enqueue(30);
  55. display();
  56.  
  57. dequeue();
  58. display();
  59.  
  60. enqueue(40);
  61. display();
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0.01s 5284KB
stdin
45
stdout
10 inserted
20 inserted
30 inserted
Queue: 10 20 30 
10 deleted
Queue: 20 30 
40 inserted
Queue: 20 30 40