fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SIZE 5
  4.  
  5. int Queue[SIZE];
  6. int TOP = -1, PTR = -1;
  7.  
  8. void push(int data){
  9. if(TOP == -1 && PTR == -1){
  10. TOP = TOP + 1;
  11. PTR = PTR + 1;
  12. Queue[PTR] = data;
  13. }else{
  14. PTR = PTR + 1;
  15. Queue[PTR] = data;
  16. }
  17. }
  18.  
  19. void peek(){
  20. printf("The element is : %d \n", Queue[TOP]);
  21. }
  22.  
  23. void printQueue(){
  24. if(TOP == -1 && PTR == -1){
  25. printf("The Queue is empty");
  26. }else{
  27. for(int i=0; i<=PTR; i++){
  28. printf("%d ", Queue[i]);
  29. }
  30. printf("\n");
  31. }
  32. }
  33.  
  34. void deleteQueue(){
  35. if(TOP==-1 && PTR==-1){
  36. printf("The Queue is empty");
  37. }else{
  38. PTR = PTR - 1;
  39. }
  40. }
  41.  
  42. int main(){
  43. push(12);
  44. push(67);
  45. printQueue();
  46. push(23);
  47. printQueue();
  48. peek();
  49. deleteQueue();
  50. printQueue();
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
12 67 
12 67 23 
The element is : 12 
12 67