fork download
  1. #include <stdio.h>
  2.  
  3. int main( )
  4. {
  5. int queue[10];
  6. int max,num,i,item;
  7. int front,rear;
  8. //printf("Enter the size of queue");
  9. scanf("%d",&max);
  10. //printf("Enter the no of elements in queue");
  11. scanf("%d",&num);
  12. //printf("Enter the elements of queue");
  13. printf("Queue before insertion : ");
  14. for(i=0;i<num;i++)
  15. {
  16. scanf("%d",&queue[i]);
  17. printf(" %d\t",queue[i]);
  18. }
  19. printf("\n");
  20. front = 0;
  21. rear = num -1 ;
  22. printf("Front end : %d\n",front);
  23. printf("Rear end : %d\n",rear);
  24. if (rear == max-1)
  25. {
  26. printf("Overflow");
  27. }
  28. else
  29. {
  30. //printf("Enter the item you want to insert \n");
  31. scanf("%d",&item);
  32. rear = rear + 1;
  33. front = 0;
  34. queue[rear] = item;
  35. printf("Queue after insertion :");
  36. for(i=0;i<=rear;i++)
  37. {
  38. printf(" %d\t",queue[i]);
  39. }
  40. printf("\n");
  41. printf("Front end : %d\n",front);
  42. printf("Rear end : %d\n",rear);
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2252KB
stdin
10
5

25
40
30
10
20

15
stdout
Queue before insertion :  25	 40	 30	 10	 20	
Front end : 0
Rear end : 4
Queue after insertion : 25	 40	 30	 10	 20	 15	
Front end : 0
Rear end : 5