Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Implementation of Queue Using Array in C

    • 0
    • 3
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 616
    Comment on it

    The below example shows the concept of FIFO. The First Inserted Element is shown at first position and if you want to retrieve the element then first inserted element will be retrieved first.

    #include<stdio.h>
    #include<conio.h>
    #include<process.h>
    void insert();
    void retrive();
    void disp();
    
    int arr[5];
    int top=0,last=-1;
    
    void main()
    {
    int ch;
    clrscr();
        while(1)
        {
            printf("\n1:Insert");
            printf("\n2:Retrive");
            printf("\n3:Display");
            printf("\n4:Exit");
            printf("\n\tPlease Enter Your Choice:-");
            scanf("%d",&ch);
    
            switch(ch)
            {
                case 1:
                insert();
                break;
    
                case 2:
                retrive();
                break;
    
                case 3:
                disp();
                break;
    
                case 4:
                exit(1);
    
                default:
                printf("\n\tYou Have Entered Wrong Choice");
                break;
            }
        }
    getch();
    }
    
    void insert()
    {
    last++;
    
        if(last==5)
        {
            printf("\n\tQueue is Overflow Stop Inserting Element");
            last--;
        }
        else
        {
    
            printf("\n\tEnter the Element:=");
            scanf("%d",&arr[last]);
        }
    }
    
    void retrive()
    {
    
        if(last<top)
        {
            printf("\n\tQueue is Empty No Element to Retrive");
        }
        else
        {
            printf("\n\t %d is Retrive",arr[top]);
            top++;
        }
    
    }
    
    void disp()
    {
    int ele=top;
        if(top>last)
        {
              printf("\n\tQueue is Empty No Element Please Insert Element");
        }
        else
        {
    
            while(ele<=last)
            {
                printf("\n\t%d",arr[ele]);
                ele++;
            }
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: