-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcqueue.c
93 lines (93 loc) · 2.19 KB
/
cqueue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<stdio.h>
#include<conio.h>
typedef struct cqueue
{
int info;
struct cqueue *next;
}node;
void insert(node **,node **);
void delet(node **,node**);
void display(node *,node *);
void main()
{
node *front=NULL,*rear=NULL;
int ch;
do
{
printf("\npress 1 to insert the element : ");
printf("\npress 2 to delete the element : ");
printf("\npress 3 to display the queue : ");
printf("\npress 4 to exit from main : ");
printf("\nEnter choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert(&front,&rear);
break;
case 2:
delet(&front,&rear);
break;
case 3:
display(front,rear);
break;
case 4:
exit(0);
default:
printf("\nInvalid choice :");
}
getch();
}while(1);
}
void insert(node **front,node **rear)
{
node *newnode;
newnode=(node*)malloc(sizeof(node));
printf("\nEnter the node value : ");
scanf("%d",&newnode->info);
newnode->next=NULL;
if(*rear==NULL)
*front=*rear=newnode;
else
{
(*rear)->next=newnode;
*rear=newnode;
}
(*rear)->next=front;
}
void delet(node **front,node **rear)
{
node *temp;
temp=*front;
if(*front==NULL)
printf("\nEmpty :");
else
{
if(*front==*rear)
{
printf("\n%d",(*front)->info);
*front=*rear=NULL;
}
else
{
printf("\n%d",(*front)->info);
*front=(*front)->next;
(*rear)->next=*front;
}
free(temp);
}
}
void display(node *front,node *rear)
{
node *temp;
temp=front;
if(front==NULL)
printf("\nEmpty");
else
{
printf("\n");
for(;temp!=rear;temp=temp->next)
printf("\n%d \t",temp->info);
printf("\n%d \t",temp->info);
}
}