-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBashemin Parking.c
73 lines (58 loc) · 1.09 KB
/
Bashemin Parking.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
#include<stdio.h>
#define size 10
typedef struct stack{
char a[size];
int top;
}Stack;
void init(Stack *p)
{
p->top=-1;
}
void push(Stack *p,char v)
{
if(p->top == size-1)
{
printf("Lane is full. Car cannot enter\n");
}
else{
p->top+=1;
p->a[p->top]=v;
}
}
int pop(Stack *p)
{
int i,c=0;
if(p->top != -1 && p->a[p->top] == "D")
{
for(i=p->top-1;i>-1;i--)
{
if(p->a[i] == "D")
c++;
}
}
p->top--;
return c;
}
char peek(Stack *p)
{
return p->a[p->top];
}
void main()
{
char car[size][2];
Stack s;
init(&s);
int i,j,n;
for(i=0;i<=size;i++)
{
printf("enter the car details\n");
scanf("%s",&car[i][0]);
scanf("%s",&car[i][1]);
push(&s,car[i][0]);
}
for(i=0;i<size;i++)
{
n=pop(&s);
printf("The car no. %s was moved out %d to allow other cars to depart.\n",car[i][1],n);
}
}