Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int *a;
- int count, size;//Initially the size of the queue is not initiallized
- void enqueue(int value){
- a[count++] = value;
- }
- void dequeue(){
- int i;
- for(i = 0; i<count-1; i++) a[i] = a[i+1];//Overwriting
- count--;
- }
- void display(){
- int i;
- printf("The queue is ");
- if(count == 0) printf("empty.");
- else{
- if(count == size) printf("full.\n");
- for(i = 0; i < count; i++) printf("%d\t", a[i]);
- }
- }
- int main(){
- int value, choice;
- printf("Enter the size of the Queue: ");
- scanf("%d", &size);
- a = (int *) malloc(sizeof(int) *size);
- while(1){
- display();
- printf("\n\n1.Enqueue 2.Dequeue 3.Exit: ");
- scanf("%d", &choice);
- switch(choice){
- case 1:
- if(count < size){
- printf("\nEnter a value to enqueue: ");
- scanf("%d", &value);
- enqueue(value);
- }else printf("Error: Overflow.");
- break;
- case 2:
- if(count > 0) dequeue();
- else printf("Error: Underflow.");
- break;
- case 3:
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement