IT HOME Programming care

IT HOME Programming Care

Sunday, January 29, 2017

Circular Queue in Data Structure with C Programming


Circular Queue in Data Structure with C Programming
Circular Queue in Data Structure with C Programming


//Circular Queue in Data Structure with C Programming
#include<stdio.h>
main()
{
    int front=0,rear=0,n=6;
    int queue[n];
    int item;
    //rear=rear-1%n;
    //printf("rear= %d",rear);
    while(1){
            //take an item
        printf("\nenter a value:  ");
        scanf("%d",&item);
        //rear position increase
        rear=(rear+1)%n;
        //check queue is full or empty
        if(rear==front){
            rear=(rear-1)%n;
            printf("\nthe queue is full.");
            //printf("\n\nand r=%d",rear);
            break;
        }
        //enqueue the item
        else{
            queue[rear]=item;
            printf("\nthe input value is: %d \nand the index number is: %d",item,rear);
        }
    }
}


Circular Queue  with user given size in Data Structure with C Programming
Circular Queue with user given size

//Solution-2: Enqueue in C Programming

#include<stdio.h>

main(){

    int front=0,rear=0,size;

    int item;

    printf("Enter the Queue size:");

    scanf("%d",&size);

    int queue[size];

    while(1){

        //take an item

        printf("\nenter a value:  ");

        scanf("%d",&item);

        //rear position increase

        rear=(rear+1)%size;

        //check queue is full or empty

        if(rear==front){

            rear=(rear-1)%size;

            printf("\nthe queue is full.");

            //printf("\n\nand r=%d",rear);

            break;

        }

        //enqueue the item

        else{

            queue[rear]=item;

            printf("\nthe input value is: %d \nand the index number is: %d",item,rear);

        }

    }

}

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