-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject_Class_Sorting.cpp
More file actions
72 lines (67 loc) · 1.01 KB
/
Object_Class_Sorting.cpp
File metadata and controls
72 lines (67 loc) · 1.01 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
#include <bits/stdc++.h>
using namespace std;
class Time
{
public:
int start, finish;
Time()
{
}
Time(int s, int f)
{
start = s;
finish = f;
}
void print()
{
cout << "start :" << start << " || finish :" << finish << endl;
}
};
bool operator<(const Time &t1, const Time &t2) //now we will do operator overloading
{
if (t1.finish < t2.finish)
{
return true;
}
if (t1.finish > t2.finish)
{
return false;
}
if (t1.start > t2.start)
{
return true;
}
return false;
}
int main()
{
//freopen("Time.txt","r",stdin);
int n;
cin >> n;
Time time[n]; //This time[] is array of our Time class
int s, f;
for (int i = 0; i < n; i++)
{
cin >> s >> f;
Time t(s, f);
time[i] = t;
time[i].print();
}
cout << endl;
sort(time, time + n);
for (int i = 0; i < n; i++)
{
time[i].print();
}
}
/*
input
7
1 2
8 9
7 2
5 4
6 2
5 10
2 3
*/