0% found this document useful (0 votes)
20 views2 pages

Queues Linkedlist 1

Need help
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Queues Linkedlist 1

Need help
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

QUEUES USING LINKED LIST

#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * link;
};
struct node *front=NULL,*rear=NULL;

void enqueue ();


void dequeue();
void display();
int main()
{
int ch;
while(1)
{
printf("1.enqueue\n 2.dequeue \n 3.display \n 4.exit \n");
printf("enter a choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:enqueue();
break;
case 2: dequeue();
break;
case 3:display();
break;
case 4:exit(0);
break;
}

}
}
void enqueue()
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
printf("enter the data \n");
scanf("%d",&temp->data);
temp->link=NULL;

if(front=rear==NULL)
{
front=rear=temp;
}
else
{
rear->link=temp;
rear=temp;
}
}
void dequeue()
{
struct node *temp;
if(front==NULL)
printf("queue is empty\n");
else
{
temp= front->link;
free(front);
front=temp;
}

}
void display()
{
struct node *temp;
temp=front;
if(front==NULL)
printf("queue is empty\n");
else
{
while(temp!=NULL)
{
printf("%d\t ",temp->data);
temp=temp->link;
}
}
}

You might also like