Static Implementation of Linear Queue
CODE
👇
- #include <stdio.h>
- #define MAX 50
- typedef struct
- {
- int data[MAX];
- int front, rear;
- }QUEUE;
- void initQ(QUEUE *pq)
- {
- pq->front = pq->rear = -1;
- }
- void addQ(QUEUE *pq, int num)
- {
- pq->rear++;
- pq->data[pq->rear] = num;
- }
- int delQ(QUEUE *pq)
- {
- int num;
- pq->front++;
- num=pq->data[pq->front];
- return (num);
- }
- int isempty(QUEUE *pq)
- {
- return(pq->front == pq->rear);
- }
- int isfull(QUEUE *pq)
- {
- return(pq->rear == MAX-1);
- }
- void main()
- {
- int n, choice;
- QUEUE q1;
- initQ(&q1);
- printf(">>Static Implementation Of Queue<<");
- do
- {
- printf("\n1.ADD \n");
- printf("2.DELETE \n");
- printf("3.EXIT \n");
- printf("Enter Your Choice: \t");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- printf("Enter Element To Be Added:");
- scanf("%d", &n);
- if(isfull(&q1))
- printf(">>Queue Overflow<<");
- else
- addQ(&q1, n);
- break;
- case 2:
- if(isempty(&q1)==1)
- printf(">>Queue Is Empty<<");
- else
- printf("The Deleted Element Is:%d \n", delQ(&q1));
- break;
- case 3:
- printf("\t>>End <<\n");
- break;
- default:
- printf(">>Enter Right Choice<<\n");
- break;
- }
- }while(choice!=3);
- }
👉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
Post a Comment