adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to implement queue Using Structure.


Program in C to implement queue Using Structure.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
 struct Queue{
     int data;
     struct Queue *next;
   };
  typedef struct Queue Queue;
       Queue *front=NULL,*rear=NULL;
        void insert(int d);
        void del();
        void show();
        int length();
   void insert(int d)
    {
        Queue *newN;
        newN=(Queue*)malloc(sizeof(Queue));
        newN->data=d;
        newN->next=NULL;
        if(front==NULL)
        {
            front=newN;
            rear=newN;
        }
        else
        {
            rear->next=newN;
            rear=newN;
        }
    }
    void del()
     {
         Queue *temp;
         int d;
         if(front==NULL){
            printf("Queue is empty!");
         }
         else
         {
            temp=front;
            d=temp->data;
            printf("\nDelete data = %d",d);
            front=temp->next;
            free(temp);
         }

     }
    void show()
     {
         Queue *temp;
         temp=front;
         while(temp!=NULL)
         {
             printf("%4d",temp->data);
             temp=temp->next;
         }
     }
     int length()
      {
         Queue *temp;
         int count=0;
         temp=front;
         while(temp!=NULL)
         {
             count++;
             temp=temp->next;
         }
         return count;
      }
   int main()
    {
      insert(23);
      insert(89);
      insert(56);
      insert(23);
      insert(12);
      insert(17);
      printf("\nElements of queue ");
      show();
      printf("\nSize of queue = %d",length());

      del();
      return 0;
    }

Output :-



Related Programs
  1.  Program in C and C++ to implement queue Using Array second method.
  2.  Program in  C++ to implement queue Using  Class.
  3.  Program in C and C++ to implement queue Using Array and Function.
  4.  Program in C++ to implement queue Using Template feature.

Post a Comment

0 Comments