#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct queue
{
int no;
struct queue *next;
};
typedef struct queue que;
void insert();
void del();
void display();
que *front=NULL,*rear=NULL;
void main()
{
int ch;
char choice;
clrscr();
do
{
printf("\t\t\tDynamic queue\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Exit\n");
printf("Enter your choice=");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit();
default:
printf("Sorry wrong choice...!!\n");
}
printf("Do you wish to continue..:");
fflush(stdin);
scanf("%c",&choice);
}while(choice=='y'||choice=='Y');
}
void insert()
{
if(rear==NULL && front==NULL)
{
front=(que *)malloc(sizeof(que));
rear=front;
rear->next=NULL;
}
else
{
rear->next=(que *)malloc(sizeof(que));
rear=rear->next;
rear->next=NULL;
}
printf("Enter a value to insert-->");
scanf("%d",&rear->no);
}
void del()
{
que *t;
if(rear==NULL||front==NULL)
{
printf("Queue is empty\n");
}
else
{
t=front;
front=front->next;
printf("deleted value=%d\n",t->no);
free(t);
}
}
void display()
{
que *ptr;
ptr=front;
while(ptr!=NULL)
{
printf("\nDisplay%d\n",ptr->no);
ptr=ptr->next;
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
#include<conio.h>
#include<malloc.h>
struct queue
{
int no;
struct queue *next;
};
typedef struct queue que;
void insert();
void del();
void display();
que *front=NULL,*rear=NULL;
void main()
{
int ch;
char choice;
clrscr();
do
{
printf("\t\t\tDynamic queue\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Exit\n");
printf("Enter your choice=");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit();
default:
printf("Sorry wrong choice...!!\n");
}
printf("Do you wish to continue..:");
fflush(stdin);
scanf("%c",&choice);
}while(choice=='y'||choice=='Y');
}
void insert()
{
if(rear==NULL && front==NULL)
{
front=(que *)malloc(sizeof(que));
rear=front;
rear->next=NULL;
}
else
{
rear->next=(que *)malloc(sizeof(que));
rear=rear->next;
rear->next=NULL;
}
printf("Enter a value to insert-->");
scanf("%d",&rear->no);
}
void del()
{
que *t;
if(rear==NULL||front==NULL)
{
printf("Queue is empty\n");
}
else
{
t=front;
front=front->next;
printf("deleted value=%d\n",t->no);
free(t);
}
}
void display()
{
que *ptr;
ptr=front;
while(ptr!=NULL)
{
printf("\nDisplay%d\n",ptr->no);
ptr=ptr->next;
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
No comments:
Post a Comment