Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

simple queue with array

Posted By: Huberta Miller     Category: C Programming     Views: 25119

Write a program of simple queue with array.

Code for simple queue with array in C Programming

#include<conio.h>
#include<stdio.h>
#define N 6

int queue[N]={0};
int rear=0,front=0;

void insert(void);
void del(void);
void disp(void);
void cre(void);

void main()
{
    int user=0;

    clrscr();
    while(user!=4)
    {
        clrscr();
        printf("\n\n\n\t\t\t THE SIZE OF QUEUE IS %d",N);
        printf("\n\t 1.INSERT");
        printf("\n\t 2.DELETE");
        printf("\n\t 3.DISPLAY");
        printf("\n\t 4.EXIT");
        printf("\n\t 5.CREATE");
        scanf("%d",&user);
        switch(user)
        {
            case 1:
                insert();
                break;
            case 2:
                del();
                break;
            case 3:
                disp();
                break;
            case 4:
                printf("\n\t THANK U");
                break;
            case 5:
                cre();
                break;
        }
        getch();

    }
    getch();
}



/*********************insert********************/
void insert(void) { int t; if(rear<N) { printf("\n\t ENTER A VALUE IN QUEUE"); scanf("%d",&t); queue[rear]=t; rear++; } else { printf("\n\t Q OVERFLOW!!!!!!!!!!!!!!!"); } } void del(void) { int i; printf("\n\t %d gets deleted.........",queue[front]); queue[front]=0; front++; } void disp(void) { int i; for(i=front;i<rear;i++) { printf("\n\t %d",queue[i]); } } void cre(void) { int t; printf("\n\t ENTER A VALUE IN QUEUE"); scanf("%d",&t); front=0; queue[front]=t; rear=front+1; }
  
Share: 


Didn't find what you were looking for? Find more on simple queue with array Or get search suggestion and latest updates.

Huberta Miller
Huberta Miller author of simple queue with array is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Deepak Sharma from India Comment on: Jul 17
How can we find the free space in Queue?
eg. I've inserted 10,20,30 in a Queue with size=5. Then Free space is 2. How can i get that? can you please tell me?

View All Comments