linear queue using linked list
linear queue using linked list
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
struct node
{
int info;
struct node *link;
};
struct node *front=NULL,*rear=NULL;
void insertion();
void deletion();
void display();
int main()
{
int choice;
do
{
system("cls");
printf("====SELECT YOUR CHOICE=====\n press 1 for insert value-\n press 2 for display the element\n press 3 for delete-----\n enter choice=");
scanf("%d",&choice);
switch(choice)
{
case 1:
insertion(); break;
case 2:
display(); break;
case 3:
deletion(); break;
default:
printf("invalid choice!");
}
}
while(choice>=1||choice<=3);
}
void insertion()
{
struct node *new1;
new1=(struct node*)malloc(sizeof(struct node));
printf("enter the value of node");
scanf("%d",&new1->info);
new1->link=NULL;
if(front==NULL)
front=rear=new1;
else{
rear->link=new1;
rear=new1;
}
}
void display()
{
struct node *temp;
if(front==NULL)
printf("queue is underflow");
else{
temp=front;
do
{
printf("%d\n",temp->info);
temp=temp->link;
}
while(temp!=NULL);
}
system("pause");
}
void deletion()
{
if(front==NULL)
printf("queue is underflow");
else{
printf("deleted recode=%d",front->info);
if(front==rear)
front=rear=NULL;
else
front=front->link;
}
system("pause");
}
#include<conio.h>
#include<stdlib.h>
#include<process.h>
struct node
{
int info;
struct node *link;
};
struct node *front=NULL,*rear=NULL;
void insertion();
void deletion();
void display();
int main()
{
int choice;
do
{
system("cls");
printf("====SELECT YOUR CHOICE=====\n press 1 for insert value-\n press 2 for display the element\n press 3 for delete-----\n enter choice=");
scanf("%d",&choice);
switch(choice)
{
case 1:
insertion(); break;
case 2:
display(); break;
case 3:
deletion(); break;
default:
printf("invalid choice!");
}
}
while(choice>=1||choice<=3);
}
void insertion()
{
struct node *new1;
new1=(struct node*)malloc(sizeof(struct node));
printf("enter the value of node");
scanf("%d",&new1->info);
new1->link=NULL;
if(front==NULL)
front=rear=new1;
else{
rear->link=new1;
rear=new1;
}
}
void display()
{
struct node *temp;
if(front==NULL)
printf("queue is underflow");
else{
temp=front;
do
{
printf("%d\n",temp->info);
temp=temp->link;
}
while(temp!=NULL);
}
system("pause");
}
void deletion()
{
if(front==NULL)
printf("queue is underflow");
else{
printf("deleted recode=%d",front->info);
if(front==rear)
front=rear=NULL;
else
front=front->link;
}
system("pause");
}
Comments
Post a Comment