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