QUEUE USING LINKED LIST : Program to Implement Queue using Linked List Testing Notes | EduRev

Testing : QUEUE USING LINKED LIST : Program to Implement Queue using Linked List Testing Notes | EduRev

 Page 1


www.eazynotes.com Gursharan Singh Tatla Page No. 1 
 
QUEUE USING LINKED LIST 
 
/****    Program to Implement Queue using Linked List    ****/ 
 
#include<stdio.h> 
 
struct node 
{ 
 int info; 
 struct node *link; 
}*front = NULL, *rear = NULL; 
 
void insert(); 
void delet(); 
void display(); 
 
int item; 
 
main() 
{ 
 int ch; 
 
 do 
 { 
  printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n"); 
      printf("\nEnter your choice: "); 
      scanf("%d", &ch); 
       
switch(ch) 
      { 
       case 1: 
            insert(); 
               break; 
                      
               case 2: 
              delet(); 
                    break; 
                           
              case 3: 
                display(); 
                break; 
                      
case 4: 
             exit(0); 
  
 
Page 2


www.eazynotes.com Gursharan Singh Tatla Page No. 1 
 
QUEUE USING LINKED LIST 
 
/****    Program to Implement Queue using Linked List    ****/ 
 
#include<stdio.h> 
 
struct node 
{ 
 int info; 
 struct node *link; 
}*front = NULL, *rear = NULL; 
 
void insert(); 
void delet(); 
void display(); 
 
int item; 
 
main() 
{ 
 int ch; 
 
 do 
 { 
  printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n"); 
      printf("\nEnter your choice: "); 
      scanf("%d", &ch); 
       
switch(ch) 
      { 
       case 1: 
            insert(); 
               break; 
                      
               case 2: 
              delet(); 
                    break; 
                           
              case 3: 
                display(); 
                break; 
                      
case 4: 
             exit(0); 
  
 
www.eazynotes.com Gursharan Singh Tatla Page No. 2 
 
               default: 
              printf("\n\nInvalid choice. Please try again...\n"); 
          } 
 } while(1); 
     getch(); 
} 
 
void insert() 
{ 
 printf("\n\nEnter ITEM: "); 
 scanf("%d", &item); 
  
 if(rear == NULL) 
 { 
  rear = (struct node *)malloc(sizeof(struct node)); 
  rear->info = item; 
  rear->link = NULL; 
  front = rear; 
 } 
 else 
 { 
  rear->link = (struct node *)malloc(sizeof(struct node)); 
  rear = rear->link; 
  rear->info = item; 
  rear->link = NULL; 
 } 
} 
 
void delet() 
{ 
 struct node *ptr; 
  
 if(front == NULL) 
  printf("\n\nQueue is empty.\n"); 
 else 
 { 
      ptr = front; 
     item = front->info; 
      front = front->link; 
      free(ptr); 
      printf("\nItem deleted: %d\n", item); 
     
          if(front == NULL) 
       rear = NULL; 
 } 
} 
 
Page 3


www.eazynotes.com Gursharan Singh Tatla Page No. 1 
 
QUEUE USING LINKED LIST 
 
/****    Program to Implement Queue using Linked List    ****/ 
 
#include<stdio.h> 
 
struct node 
{ 
 int info; 
 struct node *link; 
}*front = NULL, *rear = NULL; 
 
void insert(); 
void delet(); 
void display(); 
 
int item; 
 
main() 
{ 
 int ch; 
 
 do 
 { 
  printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n"); 
      printf("\nEnter your choice: "); 
      scanf("%d", &ch); 
       
switch(ch) 
      { 
       case 1: 
            insert(); 
               break; 
                      
               case 2: 
              delet(); 
                    break; 
                           
              case 3: 
                display(); 
                break; 
                      
case 4: 
             exit(0); 
  
 
www.eazynotes.com Gursharan Singh Tatla Page No. 2 
 
               default: 
              printf("\n\nInvalid choice. Please try again...\n"); 
          } 
 } while(1); 
     getch(); 
} 
 
void insert() 
{ 
 printf("\n\nEnter ITEM: "); 
 scanf("%d", &item); 
  
 if(rear == NULL) 
 { 
  rear = (struct node *)malloc(sizeof(struct node)); 
  rear->info = item; 
  rear->link = NULL; 
  front = rear; 
 } 
 else 
 { 
  rear->link = (struct node *)malloc(sizeof(struct node)); 
  rear = rear->link; 
  rear->info = item; 
  rear->link = NULL; 
 } 
} 
 
void delet() 
{ 
 struct node *ptr; 
  
 if(front == NULL) 
  printf("\n\nQueue is empty.\n"); 
 else 
 { 
      ptr = front; 
     item = front->info; 
      front = front->link; 
      free(ptr); 
      printf("\nItem deleted: %d\n", item); 
     
          if(front == NULL) 
       rear = NULL; 
 } 
} 
 
www.eazynotes.com Gursharan Singh Tatla Page No. 3 
 
void display() 
{ 
     struct node *ptr = front; 
      
 if(rear == NULL) 
        printf("\n\nQueue is empty.\n"); 
 else 
{ 
        printf("\n\n"); 
        
while(ptr != NULL) 
  { 
printf("%d\t",ptr->info); 
               ptr = ptr->link; 
          } 
} 
} 
 
Read More
Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

Related Searches

Exam

,

Objective type Questions

,

pdf

,

Important questions

,

Previous Year Questions with Solutions

,

study material

,

video lectures

,

QUEUE USING LINKED LIST : Program to Implement Queue using Linked List Testing Notes | EduRev

,

Free

,

shortcuts and tricks

,

QUEUE USING LINKED LIST : Program to Implement Queue using Linked List Testing Notes | EduRev

,

Sample Paper

,

MCQs

,

past year papers

,

practice quizzes

,

Extra Questions

,

mock tests for examination

,

Summary

,

Semester Notes

,

ppt

,

QUEUE USING LINKED LIST : Program to Implement Queue using Linked List Testing Notes | EduRev

,

Viva Questions

;