-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormal.cpp
More file actions
119 lines (105 loc) · 1.47 KB
/
normal.cpp
File metadata and controls
119 lines (105 loc) · 1.47 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
113
114
115
116
117
118
119
#include <bits/stdc++.h>
using namespace std;
class Car{
private:
int reg_no;
string color;
string owner;
public:
Car()
{
reg_no=0;
}
Car(int regno,string color)
{
reg_no=regno;
this.color=color;
}
};
class Slot{
private:
int slotno;
Car *parkedCar;
public:
Slot()
{
slotno=-1;
}
Slot(int slotno)
{
this.slotno=slotno;
this.parkedCar=nullptr;
}
void assignCar(Car &parkedCar)
{
this.parkCar=&parkedCar;
}
void unassignCar()
{
this.parkedCar=nullptr;
}
bool isfree()
{
return this.parkedCar==nullptr;
}
};
class ParkingScheme{
private:
priority_queue<int> pq;
public:
ParkingScheme(int capacity)
{
for(int i=1;i<=capacity;i++)
pq.push(i);
}
int giveNxtSlot()
{
if(pq.empty())
return -1;
int nxt=pq.top();
pq.pop();
return nxt;
}
void addFreeSlot(int slot)
{
pq.push(slot);
}
};
class ParkingLot{
private:
int capacity;
vector<Slot> slots;
priority_queue<int> pq;
public:
ParkingLot(int capacity)
{
this.capacity=capacity;
slots.resize(capacity+1);
for(int i=1;i<=capacity;i++)
{
pq.push(i);
slots[i]
}
}
void parkCar(Car car,const int slotno)
{
if(slots[slotno].isfree())
slots[slotno].assignCar(car);
else
{
throw "Slot is not free";
}
}
void unparkCar(const int slotno)
{
slots[slotno].unassignCar();
}
};
int main()
{
int capacity;
cout<<"Give capacity"<<endl;
cin>>capacity;
ParkingLot p=new ParkingLot(capacity);
ParkingScheme p1scheme=ParkingScheme(capacity);
}