-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathangleSort.cpp
More file actions
67 lines (60 loc) · 1.76 KB
/
angleSort.cpp
File metadata and controls
67 lines (60 loc) · 1.76 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
/**
* @file
* @author The CS2 TA Team
* @version 1.0
* @date 2013-2014
* @copyright This code is in the public domain.
*
* @brief An example of sorting (x, y) pairs by angle.
*
*/
#include "structs.hpp"
#include <vector>
// TODO Modify one of your sorting functions (bubble sort not permitted) and
// implement it here. Add extra arguments as needed.
void sort(vector<Tuple*> &points, vector<double> &angles)
{
return;
}
int main(int argc, char const *argv[])
{
vector<double> angles {4.2, 2.8, 1.4, 5.0, 3.3};
vector<Tuple*> points;
// Print the initial points and angles
for (unsigned int i = 0; i < angles.size(); ++i)
{
points.push_back(new Tuple(i, i));
}
for (vector<Tuple*>::iterator i = points.begin(); i != points.end(); ++i)
{
(*i)->printTuple();
}
for (vector<double>::iterator i = angles.begin(); i != angles.end(); ++i)
{
cout << *i << endl;
}
// Now sort them with respect to angle (points[i] corresponds to angle[i])
/** THIS IS THE ONLY LINE OF THE MAIN LOOP YOU NEED TO MODIFY. */
sort(points, angles);
/** REPLACE THE LINE ABOVE WITH A CALL TO YOUR SORTING FUNCTION. */
// and print out the new points and angles
for (vector<Tuple*>::iterator i = points.begin(); i != points.end(); ++i)
{
(*i)->printTuple();
}
for (vector<double>::iterator i = angles.begin(); i != angles.end(); ++i)
{
cout << *i << endl;
}
// Don't want to leak memory...
// Either of the below implementations works
// for (std::vector<Tuple*>::iterator i = points.begin(); i != points.end(); ++i)
// {
// delete (*i);
// }
for (unsigned int i = 0; i < points.size(); ++i)
{
delete points[i];
}
return 0;
}