Skip to main content

Static Implementation of Linear Queue

 Static Implementation of Linear Queue


CODE

👇

  1. #include <stdio.h>
  2. #define MAX 50
  3. typedef struct
  4. {
  5. int data[MAX];
  6. int front, rear;
  7. }QUEUE;

  8. void initQ(QUEUE *pq)
  9. {
  10. pq->front = pq->rear = -1;
  11. }

  12. void addQ(QUEUE *pq, int num)
  13. {
  14. pq->rear++;
  15. pq->data[pq->rear] = num;
  16. }

  17. int delQ(QUEUE *pq)
  18. {
  19. int num;
  20. pq->front++;
  21. num=pq->data[pq->front];
  22. return (num);
  23. }

  24. int isempty(QUEUE *pq)
  25. {
  26. return(pq->front == pq->rear);
  27. }

  28. int isfull(QUEUE *pq)
  29. {
  30. return(pq->rear == MAX-1);
  31. }

  32. void main()
  33. {
  34. int n, choice;
  35. QUEUE q1;
  36. initQ(&q1);
  37. printf(">>Static Implementation Of Queue<<");
  38. do
  39. {
  40. printf("\n1.ADD \n");
  41. printf("2.DELETE \n");
  42. printf("3.EXIT \n");
  43. printf("Enter Your Choice: \t");
  44. scanf("%d", &choice);
  45. switch(choice)
  46. {
  47. case 1:
  48. printf("Enter Element To Be Added:");
  49. scanf("%d", &n);
  50. if(isfull(&q1))
  51. printf(">>Queue Overflow<<");
  52. else
  53. addQ(&q1, n);
  54. break;
  55. case 2:
  56. if(isempty(&q1)==1)
  57. printf(">>Queue Is Empty<<");
  58. else
  59. printf("The Deleted Element Is:%d \n", delQ(&q1));
  60. break;
  61. case 3:
  62. printf("\t>>End <<\n");
  63. break;
  64. default:
  65. printf(">>Enter Right Choice<<\n");
  66. break;
  67. }
  68. }while(choice!=3);
  69. }


👉Execute👈


//OUTPUT

/*

>>Static Implementation Of Queue<<

1.ADD

2.DELETE

3.EXIT

Enter Your Choice:      1

Enter Element To Be Added:5


1.ADD

2.DELETE

3.EXIT

Enter Your Choice:      2

The Deleted Element Is:5


1.ADD

2.DELETE

3.EXIT

Enter Your Choice:      4

>>Enter Right Choice<<


1.ADD

2.DELETE

3.EXIT

Enter Your Choice:      3

        >>End <<

*/




                                                                                          //ThE ProFessoR

Comments