Logo 
Search:

C Programming Articles

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

CREATE A DYNAMIC SIMPLE QUEUE

Posted By: Ellis Evans     Category: C Programming     Views: 8735

Program to CREATE A DYNAMIC SIMPLE QUEUE.

Code for CREATE A DYNAMIC SIMPLE QUEUE in C Programming

#include<stdio.h>
#include<conio.h>

struct queue
{
int info;
struct queue *link;
};
struct queue *start=NULL;

constint n=5;
int q[5];
int f=-1;
int r=-1;
int i=0;
void main()
{
int ch;
while(ch!=4)
{
clrscr();
printf("1 for Insert\n");
printf("2 for Delete\n");
printf("3 for Display\n");
printf("4 for Exit\n");
printf("\nEnter ur choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: qinsert();
    break;
case 2: qdelete();
    break;
case 3: display();
    break;
case 4: break;
}
}
}

qinsert()
{
struct queue *new,*temp;
if(i>5)
 {
 printf("The queue is full\n");
 getch();
 }
else
 {
 new=(struct queue *)malloc(sizeof(struct queue));
 printf("Please enter info: ");
 scanf("%d",&new->info);
 new->link=start;
 start=new;
 i++;
 }
}

qdelete()
{
struct queue *temp;
int n=0,j;
for(temp=start;temp!=NULL;temp=temp->link)
   {
   n++;
   }
if(n==0)
   {
   printf("There is node in the Queue");
   getch();
   }
elseif(n==1)
   {
   temp=start->link;
   start=temp;
   }
else
   {
     temp=start;
     for(j=0;j<n-2;j++)
     {
      temp=temp->link;
     }
     temp->link=NULL;
   }
}

display()
{
struct queue *temp;
printf("\nThe Queue Info\n");
for(temp=start;temp!=NULL;temp=temp->link)
  {
  printf("%d ",temp->info);
  }
getch();
}
  
Share: 


Didn't find what you were looking for? Find more on CREATE A DYNAMIC SIMPLE QUEUE Or get search suggestion and latest updates.

Ellis Evans
Ellis Evans author of CREATE A DYNAMIC SIMPLE QUEUE is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

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

 
Ng Chungneng from Malaysia Comment on: Apr 17
hi~
sorry for disturb.

may explain what you struct queue *link; for
and hot the delection work?

View All Comments