-
Notifications
You must be signed in to change notification settings - Fork 0
/
Producer-Consumer Queue.c
67 lines (65 loc) · 1.01 KB
/
Producer-Consumer Queue.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
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main()
{
int n,i,j=0,k=1,r,g=0;
printf("Enter the memory space\n");
scanf("%d",&n);
printf("\n");
int a[n];
while(k=1)
{
printf("Press\n1. producer\n2.Consumer\n");
scanf("%d",&i);
printf("\n");
switch(i)
{
case 1:
{
if((j-1)!=n)
{
printf("Enter the product\n\n");
scanf("%d",&a[j]);
j++;
}
else
{
printf("Cannot produce more\n\n");
}
printf("top points to %d\n",a[g]);
for(r=j-1;r>=0;r--)
{printf("%d ",a[r]);}
printf("\n");
break;
}
case 2:
{
if(j!=0)
{
printf("The Product is %d\n",a[g]);
g++;
}
else
{
printf("No product to display\n");
}
printf("top points to %d\n",a[g]);
for(r=j-1;r>=0;r--)
{printf("%d ",a[r]);}
printf("\n");
break;
}
default:
{
printf("Dont try to be oversmart\n");
}
}
printf("press 1 to continue and 0 to exit\n");
scanf("%d",&k);
if(k==0)
{
break;
}
}
}