| |
| |
| |
| #include <stdio.h> |
| #include <conio.h> |
| #include <process.h> |
| |
| struct queue |
| { |
| int rear, front; |
| int q[5]; |
| }; |
| |
| void insert(struct queue *); |
| void delet(struct queue *, int); |
| void display(struct queue *); |
| |
| void main() |
| { |
| int i, a; |
| struct queue x; |
| clrscr(); |
| |
| x.rear = x.front = -1; |
| |
| while (i != 6) |
| { |
| printf("\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT"); |
| printf("\nEnter Your Choice:-"); |
| scanf("%d", &i); |
| |
| switch (i) |
| { |
| case 1: |
| clrscr(); |
| insert(&x); |
| display(&x); |
| break; |
| |
| case 2: |
| clrscr(); |
| delet(&x, a); |
| display(&x); |
| break; |
| |
| case 3: |
| clrscr(); |
| display(&x); |
| getch(); |
| clrscr(); |
| break; |
| |
| case 4: |
| clrscr(); |
| printf("\n\n\n\t\t\t\tBYE"); |
| exit(0); |
| } |
| } |
| getch(); |
| } |
| void insert(struct queue *p) |
| { |
| int a; |
| printf("\nEnter the element to be inserted\n"); |
| scanf("%d", &a); |
| if ((*p).rear == 4) |
| { |
| (*p).rear = -1; |
| } |
| |
| if ((*p).rear >= 4) |
| { |
| printf("STACK IS OVERFLOW"); |
| } |
| else |
| { |
| (*p).rear += 1; |
| (*p).q[(*p).rear] = a; |
| } |
| if ((*p).front == (*p).rear) |
| { |
| printf("\nThe queue is full can not insert a value\n"); |
| goto d; |
| } |
| d: |
| } |
| void delet(struct queue *p, int a) |
| { |
| if ((*p).front == (*p).rear) |
| { |
| printf("\nThe queue is empty can not delete a value\n"); |
| goto d; |
| } |
| if ((*p).front == 4) |
| (*p).front = -1; |
| else |
| { |
| (*p).front += 1; |
| a = (*p).q[(*p).front]; |
| printf("\nThe Value Deleted is %d\n", a); |
| } |
| d: |
| } |
| void display(struct queue *p) |
| { |
| int i, j; |
| if ((*p).rear > (*p).front) |
| { |
| for (i = (*p).front + 1; i <= (*p).rear; i++) |
| printf("\n\t\ts[%d] = %d ", i, (*p).q[i]); |
| } |
| else if ((*p).rear < (*p).front) |
| { |
| for (i = (*p).front + 1; i <= 4; i++) |
| printf("\n\t\ts[%d]=%d", i, (*p).q[i]); |
| for (j = 0; j <= (*p).rear; j++) |
| printf("\n\t\tq[%d] = %d", j, (*p).q[j]); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
0 Comments
Do not make spam in comment box.