Tuesday, 4 November 2014

program for queue using linked list..........

#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
}*start;


void insert(int);
void delt();
void display();

int main()
{

  int a, dt;
   start = NULL;
   while(1)
     {
      printf("\n 1 for insert");
      printf("\n 2 for delt");
      printf("\n 3 for display");
      printf("\n 4 for exit");
      printf("\n Enter your choice");
      scanf("%d",&a);
      switch(a)
      {
      case 1: printf("\n Enter element to satck");
             scanf("%d",&dt);
             insert(dt);
             break;
           
          case 2: delt();    
                 break;
               
          case 3: display();
       break;

//case 4: exit(0);
 
      }
     
     }

return 0;
}

void insert(int d)
{
   struct node *x , *y;
 
   x =  (struct node*)malloc(sizeof(struct node));
 
   x->info = d;
   x->link = NULL;
   if(start == NULL)
   start = x;
   else
   {
 
      y = start;
      while(y->link!= NULL)
      {
      y = y->link;
      }
      y->link= x;
}
}
 
void delt()
{
struct node  *y;

if(start == NULL)
printf("\n Queue is empty,Deletion is not possible\n");
else
  {
 
  y= start;
  printf("\n deleted element is\t %d ",y->info);
  start = y->link;
  free(y);
      }
}  
 
void display()  
{
    struct node  *y;

if(start == NULL)
{

printf("\n Queue is empty,Deletion is not possible\n");
}
else
{
y= start;
printf("\n Element of Queue are..........\n");
while(y!=NULL)
{
printf("\t %d",y->info);
y= y->link;
}
    }
 }
 
 
   

No comments:

Post a Comment

Note: only a member of this blog may post a comment.