0% found this document useful (0 votes)
5 views6 pages

A69 DS Ass12

Data structures assignment

Uploaded by

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

A69 DS Ass12

Data structures assignment

Uploaded by

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

Name: Vijayalaxmi Punekar

Class: SY BTech CSE


Batch: SA3
Roll no: A69
Subject: Data Structure

Assignment No: 12

Aim: Implementation of Queue using Linked List.

Program:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node* enq(struct node*, int);
struct node* deq(struct node*);
void display(struct node*);

void main()
{
int ch,item;
struct node *f,*r;
f=r=NULL;
while(1)
{
printf("\n1.Enq\n2.Deq\n3.Display\n4.Exit\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&item);
r=enq(r,item);
if(f==NULL)
f=r;
break;
case 2:
f=deq(f);
if(f==NULL)
r=NULL;
break;
case 3:
display(f);
break;
case 4: exit(1);
default: printf("\nWrong Choice:(");
}
}
}
struct node* enq(struct node *r,int x)
{
struct node *temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=x;
temp->next=NULL;
if(r!=NULL)
r->next=temp;
r=temp;
return r;
}

struct node* deq(struct node *f)


{
struct node *temp;
if(f==NULL)
{
printf("Queue is underflow");
return f;
}
temp=f;
f=f->next;
printf("Popped item=%d",temp->data);
free(temp);
return f;
}
void display(struct node *f)
{
struct node *p;
if(f==NULL)
{
printf("Queue is empty:");
return;
}
printf("Elements in queue are: ");
p=f;
while(p!=NULL)
{
printf("\n%d",p->data);
p=p->next;
}
}
Output:

You might also like