Queue Program using Linked List in C
#include<malloc.h>
#include<stdio.h>
struct node{
int value;
struct node *next;
};
void Init(struct node *n){
n->next=NULL;
}
void Enqueue(struct node *root,int value){
struct node *j=(struct node*)malloc(sizeof(struct node));
j->value=value;
j->next=NULL;
struct node *temp ;
temp=root;
while(temp->next != NULL)
{
temp=temp->next;
}
temp->next=j;
printf(“Value Enqueued is : %dn”,value);
}
void Dequeue(struct node *root)
{
if(root->next==NULL)
{
printf(“No Element to Dequeuen”);
}
else
{
struct node *temp;
temp=root->next;
root->next=temp->next;
printf(“Value Dequeued is : %dn”,temp->value);
free(temp);
}
}
void main()
{
struct node sample_queue;
Init(&sample_queue);
Enqueue(&sample_queue,10);
Enqueue(&sample_queue,50);
Enqueue(&sample_queue,570);
Enqueue(&sample_queue,5710);
Dequeue(&sample_queue);
Dequeue(&sample_queue);
Dequeue(&sample_queue);
}