📄 linkqueu.c
字号:
/* TO PUSH AND POP AN ELEMENT INTO THE QUEUE USING LINK ALLOCATION */
#include<stdio.h>
#include<conio.h>
typedef struct link
{
int e;
struct link *next;
}queue;
queue *front,*rear,*temp;
void insert(queue *,int ele);
int delete(queue *);
void display(queue *);
void main()
{
int ele,ch;
char yn;
queue s;
front= rear = temp = NULL;
do
{
clrscr();
printf("\t\t ****** OPERATIONS ON A LINKED QUEUE ******\n\n");
printf("1 . INSERTION\n");
printf("2 . DELETION\n");
printf("3 . EXIT\n");
printf("\t Enter Your Choice... ");
scanf("%d",&ch);
switch(ch)
{
case 1 : printf("ENTER THE ELEMENT TO PUSH INTO THE QUEUE : ");
scanf("%d",&ele);
insert(&s,ele);
display(&s);
break;
case 2 : ele = delete(&s);
display(&s);
break;
case 3 : exit(0);
break;
default : printf("\n\n\t OOPS WRONG CHOICE ENTERED!!!");
getch();
exit(0);
}
printf("\n\n DO YOU WANT TO PERFORM MORE OPERATIONS ? (Y/N)");
fflush(stdin);
scanf("%c",&yn);
}
while(yn == 'y' || yn == 'Y');
}
void insert(queue *temp,int ele)
{
temp = (queue*)malloc(sizeof (queue));
if (temp == NULL)
{
puts("\n\n\t Memory Is Full!!!");
return;
}
temp->e = ele;
temp->next = NULL;
if(rear == NULL)
front=rear = temp;
else
{
rear->next = temp;
rear = temp;
}
}
int delete(queue *temp)
{
int ele;
temp = (queue*)malloc(sizeof (queue));
if (front == NULL)
{
puts("\n Memory is Empty,no element present!!!");
return NULL;
}
temp = front;
ele = temp->e;
if(front==rear)
front=rear=NULL;
else
front = front->next;
free (temp);
printf("\n The Deleted Element Is:%d",ele);
return (ele);
}
void display(queue *temp)
{
if(front != NULL)
{
temp = (queue*)malloc(sizeof(queue));
temp = front;
printf("\n\nCONTENTS OF THE QUEUE ARE : \n ");
while(temp != NULL)
{
printf("\t%d\t",temp->e);
temp = temp->next;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -