IT HOME Programming care

IT HOME Programming Care

Tuesday, February 21, 2017

Queue Enqueue and Dequeue in Data Structure by C Programming

Queue Enqueue and Dequeue in Data Structure by C Programming
Queue in Data Structure


Dequeue Function in Data Structure


//Enqueue & Dequeue in C Programming
#include<stdio.h>
void enqueue();
int dequeue();
int stack[2],top=-1,max=2,empty=-1,s=0,f=0;
main(){
    int n;
    while(1){
        printf("\nPress [1] for Inter a value.\nPress [2] for Delete First value.\n");
        scanf("%d",&n);
        if(n==1){
            enqueue();
        }
        else if(n==2){
            dequeue();
        }
        else
            printf("You Enter a Invalid Number\n");
        }
    }
void enqueue(){
    int a;
    if(top==max){
        if(s<f){
            printf("Enter your Value: ");
            scanf("%d",&a);
            stack[s]=a;
            printf("You Enter: %d\n",stack[s]);
            s++;
        }
        else
            printf("Queue Overflow!");
       }
    else{
        top++;
        printf("Enter your Value: ");
        scanf("%d",&a);
        stack[top]=a;
        printf("You Enter: %d\n",stack[top]);
    }
}
int dequeue(){
    if(f>top){
       if(s<=max)
            s++;
       else
            printf("Queue Underflow\n");
    }
    else{
        printf("You have Deleted the value of: %d\n",stack[f]);
        f++;
    }
}

0 comments:

Post a Comment

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();

IT HOME Freelancing Care