-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
112 lines (109 loc) · 1.36 KB
/
Copy pathqueue.c
File metadata and controls
112 lines (109 loc) · 1.36 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<stdio.h>
#include<stdlib.h>
void push(int);
void pop();
void display();
void isempty();
struct node
{
int data;
struct node *p;
}*s,*temp;
int r=-1,f=0;
int main()
{
s=NULL;
int i,j,k=1,ch,ele;
while(k)
{
printf("\n1.push,\n2.pop\n3.display\n4.exit\n6.is empty\nenter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter ele:");
scanf("%d",&ele);
push(ele);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
k=k-1;
break;
case 6:
isempty();
break;
default:
printf("enter correct choice");
break;
}
}
}
void push(int ele)
{
if(s==NULL)
{
s=(struct node*)malloc(sizeof(struct node));
s->data=ele;
s->p=s;
r=r+1;
}
else
{
struct node *temp2;
temp=(struct node*)malloc(sizeof(struct node));
temp2=s->p;
s->p=temp;
s=temp;
temp->p=temp2;
temp->data=ele;
r=r+1;
}
printf("insertion successfull");
}
void pop()
{
if(s==NULL)
{
printf("q is empty");
}
else if(f==r)
{
printf("deletion successfull");
r=-1;f=0;
s=NULL;
}
else
{
temp=s->p;
s->p=temp->p;
free(temp);
f=f-1;
}
}
void display()
{
if(f>r)
printf("empty");
else
{
temp=s->p;
while(temp->p!=s->p)
{
printf("%d",temp->data);
temp=temp->p;
}
printf("%d",temp->data);
}
}
void isempty()
{
if(f>r)
printf("empty");
else
printf("not empty");
}