Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

PROGRAM NO-->9 ROLL NO->2309030

/ *WRITE A PROGRAM TO IMPLEMENT QUEUE USING POINTERS *\

#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
#include<malloc.h>
int a,n;
void insert(int);
int delete();
struct node
{
int info;
struct node*next;
};
typedef struct node node;
node*f =NULL,node*r=NULL;
void main()
{
int c;
clrscr();
printf("1:insert \n");
printf("2:delete \n");
printf("3:exit \n");
while(1)
{
printf("enter the c");
scanf("%d",&c);
switch(c)
{
case 1:
printf("enter the num to be insert");
scanf("%d",&n);
push(n);
break;
case 2:n=pop();
if(n!=-1)
printf("\nelement deleted:%d",n);
else
printf("\nqueue is empty");
break;
case 3:exit(0);
default:printf("wrong choice");
break;
}
}
}

1
PROGRAM NO-->9 ROLL NO->2309030

/ *WRITE A PROGRAM TO IMPLEMENT QUEUE USING POINTERS *\


void insert(int x)
{
node*s;
s=(node*)malloc(sizeof(node));
s->info=x;
s->next=NULL;
if(r!= NULL)
r->next=s;
r=s;
}
else
{
f=s;
r=s;
}
}
int delete()
{
int x;
node*q;
if(f!=NULL)
{
x=f->info;
q=f;
f=f->next;
free(q);
else
{
f=r= NULL;
x= NULL;
}
return(x);
}

2
PROGRAM NO-->9 ROLL NO->2309030

/ *WRITE A PROGRAM TO IMPLEMENT QUEUE USING POINTERS *\

/*OUTPUT*\

You might also like