Circular Queue using Linked List ....
#include<stdio.h>
#include<conio.h>
typedef struct circular
{
int val;
struct circular *next;
}cir;
cir *createnode(cir *,int );
void enqueue(cir **,int);
int dequeue(cir **);
int isempty(cir *);
int peek(cir *);
void disp(cir *);
void main()
{
cir *h=NULL;
int v,p;
while(1)
{
printf("\n 1.insert \n2.delete \n3.peek \n4.display \n5.exit");
printf("enter the choice");
scanf("%d",&p);
switch(p)
{
case 1:printf("enter the value");
scanf("%d",&v);
enqueue(&h,v);
break;
case 2:printf("deleted value is:");
scanf("%d",&v);
break;
case 3:printf("front value: ");
scanf("%d",&v);
break;
case 4:printf("display the value");
disp(h);
break;
case 5: exit(0);
default:printf("not a proper choice");
}
}
}
cir *createnode(cir *h,int v)
{
cir *ptr,*temp;
temp=(cir*)malloc(sizeof(cir));
temp->val=v;
temp->next=NULL;
if(h==NULL)
{
h=temp;
}
else
{
ptr=h;
while(ptr->next!=h)
ptr=ptr->next;
ptr->next=temp;
}
temp->next=h;
return h;
}
void enqueue(cir **h,int v)
{
cir *ptr,*temp;
temp=(cir *)malloc(sizeof(cir));
temp->val=v;
temp->next=NULL;
if(*h==NULL)
{
*h=temp;
}
else
{
ptr=*h;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp;
}
}
int dequeue(cir **h)
{
int p;
p=(*h)->val;
*h=(*h)->next;
return p;
}
int isempty(cir *h)
{
if(h==NULL)
return 1;
else
return 0;
}
int peek(cir *h)
{
return h->val;
}
void disp(cir *h)
{
cir *ptr;
ptr=h;
while(ptr->next!=h)
{
printf("%d",ptr->val);
ptr=ptr->next;
}
printf("%d",ptr->val);
}
I/O : detail description is coming soon ...
#include<conio.h>
typedef struct circular
{
int val;
struct circular *next;
}cir;
cir *createnode(cir *,int );
void enqueue(cir **,int);
int dequeue(cir **);
int isempty(cir *);
int peek(cir *);
void disp(cir *);
void main()
{
cir *h=NULL;
int v,p;
while(1)
{
printf("\n 1.insert \n2.delete \n3.peek \n4.display \n5.exit");
printf("enter the choice");
scanf("%d",&p);
switch(p)
{
case 1:printf("enter the value");
scanf("%d",&v);
enqueue(&h,v);
break;
case 2:printf("deleted value is:");
scanf("%d",&v);
break;
case 3:printf("front value: ");
scanf("%d",&v);
break;
case 4:printf("display the value");
disp(h);
break;
case 5: exit(0);
default:printf("not a proper choice");
}
}
}
cir *createnode(cir *h,int v)
{
cir *ptr,*temp;
temp=(cir*)malloc(sizeof(cir));
temp->val=v;
temp->next=NULL;
if(h==NULL)
{
h=temp;
}
else
{
ptr=h;
while(ptr->next!=h)
ptr=ptr->next;
ptr->next=temp;
}
temp->next=h;
return h;
}
void enqueue(cir **h,int v)
{
cir *ptr,*temp;
temp=(cir *)malloc(sizeof(cir));
temp->val=v;
temp->next=NULL;
if(*h==NULL)
{
*h=temp;
}
else
{
ptr=*h;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=temp;
}
}
int dequeue(cir **h)
{
int p;
p=(*h)->val;
*h=(*h)->next;
return p;
}
int isempty(cir *h)
{
if(h==NULL)
return 1;
else
return 0;
}
int peek(cir *h)
{
return h->val;
}
void disp(cir *h)
{
cir *ptr;
ptr=h;
while(ptr->next!=h)
{
printf("%d",ptr->val);
ptr=ptr->next;
}
printf("%d",ptr->val);
}
I/O : detail description is coming soon ...
Comments
Post a Comment